1.jQuery 使用append添加元素其中button标签不会出现,点击按钮生成了一个tr和两个td标签,button标签不会出现.预计的是生成
你需要在你的button外包一层td
$("#aqi-table").append("<tr><td>" + city + "</td><td>" + num + "</td><td><button>删除</button></td></tr>");
楼主去了解一下事件委托,append的dom是无法绑定事件的,只能通过委托的形式绑定
$("#aqi-table button").click(function(){ // })
改成
$(document).on('click',"#aqi-table button",function(){ // })
$("#aqi-city-input").val() = "";
$("#aqi-value-input").val() = "";
jquery的val()不是这样用的
而是把值放在val("")中
基础的事件委托
一.清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>");