$('#txt1').val()
または$('#txt1').text()
またはを呼び出すと、はその要素に$('#txt1').html()
設定されますか?focus
なぜなら、私はこのfocusout
ハンドラーを持っているので、それはn
回(n
グリッド内の行数)と呼ばれていますが、txtboxを1回クリックし、値を入力してTabキーを押すだけで、それfocusout
が1回だけ発生することを保証します(少なくとも手動で行いました)。ただし、n
読み取りを行う関数がある場合もある$('#txt1').val()
ので、これがテキストボックスにフォーカスを設定し、フォーカスが失われる原因になると思います。
つまり、明示的に宣言/フォーカスされていない場合でもval(), text() or html()
、呼び出しはフォーカスを要素に設定しますか?
ps:コードを投稿することもできますが、ここに投稿するには長すぎると思いますが、それでも、誰かがそれを必要としている場合は、コメントしてください!
**編集**可能な限り少ないコードを投稿しています...
var txtDiscountFocusOutHandler = function (event) {
if ($(this).val() == '') {
$(this).val('0');
}
recomputeAllGrid(1, ($('#grdEntry > tbody > tr').size()), false, true);
}
};
// Step 20.D don't add the handler in the body,
// add on keydown, that means user has explicitly changed the discount
var txtDiscountKeyDownHandler = function (event) {
// attach the handler here
$('body').on("focusout.AttachedEvent", '#txtDiscount', txtDiscountFocusOutHandler);
};
// step 21. this will recalculate all the data of lower grid
// argStart = the starting number to being counting from
// argEnd = the row to stop count at
// argCallEachRowAsUpdate = call row as updadte or not
// argAddDisAndTax = should dis and tax be added or subtracted?
function recomputeAllGrid(argStartRow, argEndRow, argCallEachRowAsUpdate, argAddDisAndTax) {
var _iCounter;
// remove the event handler
$('body').off("focusout.AttachedEvent", '#txtDiscount', txtDiscountFocusOutHandler);
// set the lblDiscount = 0;
$('#lblDisAmt').text('0');
// set the tax = 0
$('#txtSrTax').val('0');
// set the total to 0
$('#txtTotal').val('0');
// don't change the value of advance
// change the value of balance
$('#txtBalance').val('0');
// clear the alltax, and alldiscount
$('#hdnAllTax').val('');
$('#hdnAllDiscount').val('');
//$('#hdnAllDiscountFocusOut').val('0');
// for the given number of rows
var _reCompProcessArray, _reCompQty;
var _reCompPrc, _reCompRate, _reCompPrc1, _reCompRate1, _reCompPrc2, _reCompRate2;
var _reCompAllSplittedPrcRate;
for (_iCounter = argStartRow; _iCounter < argEndRow; _iCounter++) {
// find qty
_reCompQty = $('body').find('#grdEntry > tbody').find('#Qty_' + _iCounter + '').text() + '';
// find the process array for each
var _reCompProcessArray = $('body').find('#grdEntry > tbody').find('#Prc_' + _iCounter + '').text() + '';
_reCompAllSplittedPrcRate = splitPrcRateFromArray(_reCompProcessArray);
// set the variables
_reCompPrc = _reCompAllSplittedPrcRate.prc;
_reCompPrc1 = _reCompAllSplittedPrcRate.prc1;
_reCompPrc2 = _reCompAllSplittedPrcRate.prc2;
_reCompRate = _reCompAllSplittedPrcRate.rate;
_reCompRate1 = _reCompAllSplittedPrcRate.rate1;
_reCompRate2 = _reCompAllSplittedPrcRate.rate2;
// find the disAndTax
ComputeRowDisTaxAmt(_reCompPrc, _reCompRate, _reCompPrc1, _reCompRate1, _reCompPrc2, _reCompRate2, _reCompQty, false, -1, true);
}
// reset all values
setTheDefaults();
$('#grdEntry_ctl01_lblHAmount').text($('#txtCurrentDue').val());
};
// Step 6.B this function splits the array passed of rate and prc into individuals
// the format of ary is : (prc@rate),(prc1@rate1), and so on
function splitPrcRateFromArray(argPrcRateArray) {
var firstPrc, firstRate, SecondPrc, SecondRate, ThirdPrc, ThirdRate;
if (argPrcRateArray.indexOf(',') > 0) {
// there is more than 1 process
var PrcNameAndRateArray = argPrcRateArray.split(',');
// split 3 times
// first rate and prc
firstPrc = PrcNameAndRateArray[0].split("@")[0].substring(1) + '';
firstRate = PrcNameAndRateArray[0].split("@")[1] + '';
firstRate = firstRate.substring(0, firstRate.length - 1);
// second rate and prc
SecondPrc = PrcNameAndRateArray[1].split("@")[0].substring(1);
SecondRate = PrcNameAndRateArray[1].split("@")[1];
SecondRate = SecondRate.substring(0, SecondRate.length - 1);
// third rate and prc
ThirdPrc = PrcNameAndRateArray[2].split("@")[0].substring(1);
ThirdRate = PrcNameAndRateArray[2].split("@")[1];
ThirdRate = ThirdRate.substring(0, ThirdRate.length - 1);
// check for null
if (firstPrc == '') { firstPrc = '' };
if (SecondPrc == '') { SecondPrc = '' };
if (ThirdPrc == '') { ThirdPrc = '' };
if (firstRate == '') { firstRate = '0' };
if (SecondRate == '') { SecondRate = '0' };
if (ThirdRate == '') { ThirdRate = '0' };
}
else {
// there is just one item
firstPrc = argPrcRateArray.split("@")[0].substring(1) + '';
firstRate = argPrcRateArray.split("@")[1] + '';
firstRate = firstRate.substring(0, firstRate.length - 1);
SecondPrc = '';
SecondRate = '0';
ThirdPrc = '';
ThirdRate = '0';
}
// json object returned
var _returnValue =
{ 'prc': firstPrc,
'prc1': SecondPrc,
'prc2': ThirdPrc,
'rate': firstRate,
'rate1': SecondRate,
'rate2': ThirdRate
};
return _returnValue;
}
function ComputeRowDisTaxAmt(argPrc, argRate, argPrc1, argRate1, argPrc2, argRate2, argQty, argIsUpdating, argRowNumber, argIsRecomputing) {
var _curPrcDis = 0;
var _curPrcTax = 0;
var _curPrcAmount = 0;
var _curPrcDis1 = 0;
var _curPrcTax1 = 0;
var _curPrcAmount1 = 0;
var _curPrcDis2 = 0;
var _curPrcTax2 = 0;
var _curPrcAmount2 = 0;
var _curDisStr = '';
var _curTaxStr = '';
var _iCounter;
var _totalDiscOfRow = 0;
var _totalTaxOfRow = 0;
// First time
_curPrcDis = findDiscountForProcess(argPrc, argRate, true);
_curPrcAmount = findAmountForProcess(argRate, argQty, true);
_curPrcTax = findTaxForProcess(argPrc, _curPrcAmount, _curPrcDis);
_curDisStr = _curPrcDis + '';
_curTaxStr = _curPrcTax + '';
// two more times
// other checks irrelevant to this question
}
/********************************************************/
// now the function that _I think_ is causing this trouble
// the reason I think so, is because it is calling _val()_
// and I think that might be setting focus to discount box
// and so its being called _n_ times
// Step 3.D Find row discount
// It caculates the discount of current row/process
// argPrc : The process
// argPrcRate : Rate of the Process
// bApplyQty : Indicates weather to take qty into accout, that would be the case in for first process
function findDiscountForProcess(argPrc, argPrcRate, bApplyQty) {
// if prc is null, just return 0
if (argPrc == '') { return 0; };
// find the rate in discount percentage
var _discountPerc = $('#txtDiscount').val();
//alert($(document.activeElement).attr('id'));
var _qty = parseFloat($('#txtQty').val());
var _amtToCalcDisOn;
_amtToCalcDisOn = findAmountForProcess(argPrcRate, _qty, bApplyQty);
return parseFloat(_amtToCalcDisOn) * _discountPerc / 100;
};