

这种逻辑本来很简单的。代码如下:
$(".showProductInfo").append("<tr>"
+"<td></td>"
+"<td>批量设置</td>"
+'<td><input type="number" class="product_info" name="setPrice" id="setPrice" onchange="setprice()" value="" /></td>'
+'<td><input type="number" class="product_info" name="setStock" id="setStock" value="" /></td>'
+"</tr>");
$('input[name=setStock]').on("change",function(){
console.log($('[name=setStock]').val());
$('[name=stock]').val($('#setStock').val());
});我是尽量确保前面一段代码在后一段代码之前加载了,但是通过这种方式 选择不到 id=setStock的input输入框。
..............
十分钟后
我发现
$(".showProductInfo").append("<tr>"
+"<td></td>"
+"<td>批量设置</td>"
+'<td><input type="number" class="product_info" name="setPrice" id="setPrice" onchange="setprice()" value="" /></td>'
+'<td><input type="number" class="product_info" name="setStock" id="setStock" value="" /></td>'
+"</tr>");这段代码是在一个按钮出发的,
但是
$('input[name=setStock]').on("change",function(){
console.log($('[name=setStock]').val());
$('[name=stock]').val($('#setStock').val());});
我是反在了script标签的尾部了。所以按钮没有点击之前,这段代码就已经执行了,此时上面的
$(".showProductInfo").append()还没有执行!!!原因找到了!为了找到原因我还专门把第一个setprice()方法写到html中,变成html事件处理事件。 唉低级错误!!记录一下!共勉!
