我有一张桌子,允许用户输入多个库存
<table class="table1" id="table1">
<thread>
<tr>
<th scope="col">Item Name</th>
<th scope="col">Qty</th>
<th scope="col">Rate</th>
<th scope="col">Amount</th>
</tr>
</thread>
<tbody>
<tr>
<td><input type="text"/></td>
<td><input type="text" class="num" id="qty"/></td>
<td><input type="text" class="num" id="rate"/></td>
<td><input type="text" class="num" id="amt"/></td>
</tr>
</tbody>
</table>
<a id="add"><button>Add</button></a>
Run Code Online (Sandbox Code Playgroud)
这段代码是添加新行:
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
var newrow = $("<tr><td><input type="text"/></td><td><input type=\"text\" id=\"qty\"/></td><td><input type="\text\" id="\rate\"/></td><td><input type="\text\" id="\amt\"/></td></tr>");
newrow.insertAfter('#table1 tbody>tr:last');
return false;
});
$(".num").keyup(function() {
var id = $(this).attr('id');
if (id == 'qty') {
var i = parseFloat($("#rate").val())
if (!isNaN(i)) {
var …Run Code Online (Sandbox Code Playgroud) 我有一个javascript对象
function A()
{
this.ini = function()
{
$('#test').html('<button id="click" >Hi</button>');
}
$('#click').on('click',function(){
alert('Hi');
});
}
Run Code Online (Sandbox Code Playgroud)
但我有一个问题,没有使用onClick事件.
谢谢你的帮助
我只想从当前删除的图像中删除TR元素...
我这样做:
$( "#btnDelete").click(function() {
$(this).parent().parent().remove();
});
Run Code Online (Sandbox Code Playgroud)
见小提琴
我不明白为什么它不起作用
有小费吗?
我的问题是,即使我使用.on,添加了类的添加div的click事件也不会触发.这是我的页面脚本.
$(".added").on("click", function () { alert("halo") });
$("#nextAdress").on("click",function (event) {
event.preventDefault();
$("#trainerRegistrationFields").append('<div class="added">adsa</div>');
}
Run Code Online (Sandbox Code Playgroud)
你可以帮助我,所以点击事件也会在添加了类的动态添加元素上触发吗?
提前告诉你
即使这是" 事件处理程序不处理动态内容 " 的重复问题,即使按照那里给出的答案,我仍然遇到同样的问题.请帮忙 ....
userinfo.topics.forEach(ele=>{
$("#topics_subscribed").append(`<li class="list-group-item col-4">${ele} <i style="color:red;font-size:.7em;" class="removeitem fa fa-times"/></li>`) ;
});
$(document).on('click', '.removeitem', ()=> {
console.log('clicked') ;
$(this).parent().remove() ;
});
Run Code Online (Sandbox Code Playgroud)
请在将此标记为重复之前回答其原因.如何解决这个问题?(我会在答复后立即删除这个问题....)