扫码关注官方订阅号
1.jQuery 使用append添加元素其中button标签不会出现,点击按钮生成了一个tr和两个td标签,button标签不会出现.预计的是生成
2.代码:
IFE JavaScript Task 01 城市名称: 空气质量指数: 确认添加
城市名称: 空气质量指数: 确认添加
闭关修行中......
一.清val
$("#aqi-city-input").val() = ""; $("#aqi-value-input").val() = "";
==>>
$("#aqi-city-input").val(""); $("#aqi-value-input").val("");
二.绑定事件
$(document).on("click","#aqi-table button", function (event) { event.target.parentNode.parentNode.remove() })
三. 添加数据行
$("#aqi-table").append("<tr><td>" + city + "</td><td>" + num + "</td><td><button>删除</button></td></tr>");
基础的事件委托
jquery的val()不是这样用的而是把值放在val("")中
$("#aqi-table button").click(function(){ // })
改成
$(document).on('click',"#aqi-table button",function(){ // })
楼主去了解一下事件委托,append的dom是无法绑定事件的,只能通过委托的形式绑定
你需要在你的button外包一层td
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
一.清val
==>>
二.绑定事件
三. 添加数据行
基础的事件委托
$("#aqi-city-input").val() = "";
$("#aqi-value-input").val() = "";
jquery的val()不是这样用的
而是把值放在val("")中
改成
楼主去了解一下事件委托,append的dom是无法绑定事件的,只能通过委托的形式绑定
你需要在你的button外包一层td