Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 变更事件不发生';无法使用动态创建的项_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 变更事件不发生';无法使用动态创建的项

Javascript 变更事件不发生';无法使用动态创建的项,javascript,jquery,ajax,Javascript,Jquery,Ajax,变更事件 $('.amount').on('change','input', function(){ alert('hello!'); }); 动态创建的项目: <tr id="row{{$data['product_id']}}"> <td><input type="checkbox" name="product[]" value="{{$data['product_id']}}"></td> <td>

变更事件

$('.amount').on('change','input', function(){
        alert('hello!');
});
动态创建的项目:

<tr id="row{{$data['product_id']}}">
    <td><input type="checkbox" name="product[]" value="{{$data['product_id']}}"></td>
    <td>{{$data['product_id']}}</td>
    <td class="amount">{!! Form::input('number','qty',$data['qty'],['id'=>$data['product_id'],'min'=>'1','max'=>\App\Product::find($data['product_id'])->quantity,'required'=>'required'])!!}
    </td>
    <td>{{$data['stock']}}</td>
    <td id="rowprice{{$data['product_id']}}">{{$data['price']}} $</td>
    <td id="rowsum{{$data['product_id']}}">{{$data['qty']*$data['price']}} $</td>
</tr>

所以,当我尝试用新创建的项目更改数量输入的值时,事件不会触发,但当我重新加载页面时,它会触发

绑定到类、ID等时,jQuery只能绑定到页面上当前的元素。它无法预见未来。常见的修复方法是绑定到文档。很难看出您实际上想要绑定到什么,但这里有一个示例

$(document).on('change','.amount input', function(){
        alert('hello!');
});

当绑定到类、ID等时,jQuery只能绑定到页面上当前的元素。它无法预见未来。常见的修复方法是绑定到文档。很难看出您实际上想要绑定到什么,但这里有一个示例

$(document).on('change','.amount input', function(){
        alert('hello!');
});

这会有帮助吗?uhh no:C尝试了$('.amount')。on('change',$(“:input”),function(){},也尝试了使用prevent default,但仍然不起作用(((这是否有帮助?uhh no:C尝试了$('.amount')。on('change',$(“:input”),function(){},也尝试了使用prevent default,仍然不起作用(((我想把它绑定到一个td,里面有一个类数量和一个输入我想把它绑定到一个td,里面有一个类数量和一个输入