简体   繁体   English

js不是在chrome上运行,而是在firefox上运行

[英]js are not running on chrome but running on firefox

I have mention code and also dynamic code for textbox with js. 我提到了带有js文本框的代码和动态代码。 i am facing problem in chrome while running this code but this same code is running on firefox properly, so please give me some suggestion regarding this code. 我在运行此代码时遇到了chrome问题,但是同一代码在Firefox上正确运行,所以请给我一些有关此代码的建议。

  1. html code for textbox 文本框的html代码

     <td><input class="form-control" required type='text' id='productname_1' name='productname[]'/></td> <td><input class="form-control" readonly="" required type='text' id='price_1' name='price[]'/></td> <td><input class="form-control" required type='text' id='quantity_1' name='quantity[]'/></td> <td><input class="form-control" readonly="" required type='text' id='total_1' name='total[]'/> </td> 
  2. Dymamic html code for textbox 文本框的动态HTML代码

     <td><input class='form-control productname12_"+i+"' required type='text' id='productname_"+i+"' name='productname[]'onchange='myFunction()'/></td> <td><input class='form-control' readonly type='text' id='price_"+i+"' required name='price[]'/></td><td><input class='form-control' type='text' required id='quantity_"+i+"' name='quantity[]'/></td><td><input class='form-control' readonly type='text' required id='total_"+i+"' name='total[]'/></td> 
  3. js code js代码

     function myFunction() { var x = document.getElementById('productname_'+j).value; //alert(x); $.ajax({ type:"POST", url:"addplaceorder/getproductprice", data:{'name':x}, cache:false, success:function(html){ //alert(html); //alert('#price_'+k); $('#price_'+k).val(html); } }); $('#quantity_'+j).change(function(){ var val = $(this).val(); var price = $('#price_'+k).val(); //alert(name); var total = (val* price); //alert(total); totalamount = totalamount+total; //alert(totalamount); $('#total_'+k).val(total); $('#showtotal').text(totalamount); }); $('#quantity_'+j).keypress(function (e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { //display error message //$("#errmsg").html("Digits Only").show().fadeOut("slow"); return false; } }); j++;k++; } 

This might be the problem 这可能是问题所在

var x = document.getElementById('productname_'+j).value;

The variable j is not initialized, therefore the value is undefined. 变量j未初始化,因此该值未定义。 I suppose that there is not element with id "productname_undefined". 我想没有ID为“ productname_undefined”的元素。 So when you try to read value from that undefined element, you will get an error. 因此,当您尝试从该未定义元素中读取值时,将收到错误消息。 Something like "can not read property value of undefined" 诸如“无法读取未定义的属性值”之类的内容

PS: It is better to use the debugger statements, rather then alert() ; PS:最好使用debugger语句,而不要使用alert()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM