Jquery不在IE 8中工作

Jquery不在IE 8中工作,jquery,Jquery,我在jquery中编写了一段代码,用于在页面中动态添加组件 var counter = 1; var delCnt = 0; $(function() { $('#linkAddLot').click(function() { counter = eval(document.getElementById("hdnTotLot").value); delCnt = eval(document.getElementById("hdnDelLot").value

我在jquery中编写了一段代码,用于在页面中动态添加组件

var counter = 1;
var delCnt = 0;
$(function() {
    $('#linkAddLot').click(function() {
        counter = eval(document.getElementById("hdnTotLot").value);
        delCnt = eval(document.getElementById("hdnDelLot").value);
        if((eval(counter-delCnt))>=5){
            $('span.#lotMsg').css("visibility","visible");
            $('span.#lotMsg').css("color","red");
            $('span.#lotMsg').html('Already 5 (Five) Lot!!!');
        } else {
            $('span.#lotMsg').css("visibility","collapse");
            var htmlEle = "<tr id='trLot_"+ (counter+1) +"'>"+
                "<td class='t-align-center'><input type='checkbox' name='packagedetail_"+ (counter+1) +"' id='chkPackageDetail_"+ (counter+1) +"' value='"+ (counter+1) +"'/></td>"+
                "<td class='t-align-center'><input name='lotno_"+ (counter+1) +"' type='text' class='formTxtBox_1' id='txtLotNo_"+ (counter+1) +"' style='width:80px;' onBlur='chkLotNoBlank(this);chkLotNo(this);'/><span id='msgLotNo_"+ (counter+1) +"' style='color: red; ' >&nbsp;</span></td>"+
                "<td class='t-align-center'><textarea name='lotdesc_"+ (counter+1) +"' cols='20' rows='3' class='formTxtBox_1' id='txtLotDesc_"+ (counter+1) +"' style='width:250px;' onBlur='chkLotDetBlank(this);'></textarea><span id='msgLotDesc_"+ (counter+1) +"' style='color: red; '>&nbsp;</span></td>"+
                "<td class='t-align-center'><input name='quantity_"+ (counter+1) +"' type='text' class='formTxtBox_1' id='txtQuantity_"+ (counter+1) +"' style='width:80px;' onBlur='chkQtyBlank(this);'/><span id='msgLotQty_"+ (counter+1) +"' style='color: red; '>&nbsp;</span></td>"+
                "<td class='t-align-center'><input name='unit_"+ (counter+1) +"' type='text' class='formTxtBox_1' id='txtUnit_"+ (counter+1) +"' style='width:80px;' onBlur='chkUnitBlank(this);'/><span id='msgLotUnit_"+ (counter+1) +"' style='color: red; '>&nbsp;</span></td>"+
                "<td class='t-align-center'><input name='estimatecost_"+ (counter+1) +"' type='text' class='formTxtBox_1' id='txtEstimateCost_"+ (counter+1) +"' style='width:80px;' onChange='setPkgEstCost(this);' onBlur='chkEstBlank(this);'/><span id='msgLotCost_"+ (counter+1) +"' style='color: red; '>&nbsp;</span></td>"+
                "</tr>";
            $("#tblLots").append(htmlEle);
            document.getElementById("hdnTotLot").value = (counter+1);
        }
    });
});
var计数器=1;
var-delCnt=0;
$(函数(){
$('#linkAddLot')。单击(函数(){
计数器=eval(document.getElementById(“hdntlot”).value);
delCnt=eval(document.getElementById(“hdnDelLot”).value);
如果((评估(计数器增量))>=5){
$('span.#lotMsg').css(“可见性”、“可见”);
$('span.#lotMsg').css(“颜色”、“红色”);
$('span.#lotMsg').html('已经5(五)批!!!');
}否则{
$('span.#lotMsg').css(“可见性”、“折叠”);
var htmlEle=“”+
""+
" "+
" "+
" "+
" "+
" "+
"";
$(“#tblLots”).append(htmlEle);
document.getElementById(“hdntlot”).value=(计数器+1);
}
});
});
在这里,我在
onBlur='chkLotNoBlank(这个)上创建了onBlur函数;(这个);'在txtLotNo上,但在IE8中它不能工作


如果我在IE 7和firefox中运行它,我会工作得很好,如果我在windows 7预装的IE8版本IE8.0.7600.16385中工作,但是如果我在windows 2003兼容的IE 8.0.6001.18702中试用,它就不能工作了,那么有人能给我解决这个问题的方法吗?

我不能确切地说问题是什么——但使用这些评估肯定很时髦。如果不必使用eval,最好不要使用eval,因为它会消耗大量资源

试试这个:

var counter = 1; 
var delCnt = 0; 

$(function() { 
    $('#linkAddLot').click(function() { 
        counter = parseInt($("#hdnTotLot").val(),10); 
        delCnt = parseInt($("#hdnDelLot").val(),10); 
        if(((counter-delCnt)>=5){ 
            $('span.#lotMsg').css("visibility","visible"); 
            $('span.#lotMsg').css("color","red"); 
            $('span.#lotMsg').html('Already 5 (Five) Lot!!!'); 
        } else { 
            $('span.#lotMsg').css("visibility","collapse"); 
            var htmlEle = ""+ ""+ " "+ " "+ " "+ " "+ " "+ ""; 
            $("#tblLots").append(htmlEle); 
            $("#hdnTotLot").val(counter+1); 
        } 
    }); 
});

您有以下代码:

$('span.#lotMsg').css("visibility","visible"); 
$('span.#lotMsg').css("color","red"); 
$('span.#lotMsg').html('Already 5 (Five) Lot!!!');
把这个缩短到:

$('span.#lotMsg').css("visibility","visible").css("color","red").html('Already 5 (Five) Lot!!!'); 

函数
chkLotNoBlank
chkLotNo
的代码是什么?我没有看到上面发布的内容。谢谢你的建议和指导,但如果你能找到解决我实际问题的方法,我真的非常感谢你。我需要分配模糊事件处理程序和模糊处理程序本身的实际代码,为你提供一个可能的解决方案。啊,onBlur=“someFunc(this);”function someFunc(elm){if($(elm).val()==“”)警报(空);}更友好的是$('elm').blur(函数(){if($(this).val()==“”)警报(空);});但这并不能解决实际问题。这种类型的建议更适合作为问题的注释。