我想为HTML中的每一行提供一个id,当我在textbox中输入该值时,我希望jquery删除该行。
我已经建立了这个小提琴
$(document).ready(function(){
$("#addbutton").click(function(){
var uniqueid = $("#textbox1").val();
var text = $("#textbox2").val();
$("<tr><td>row content</td></tr>").val(uniqueid).html(text).appendTo("#table1");
});
$("#removebutton").click(function(){
var uniqueid = $("#textbox1").val();
//I want to find row with uniqueid, and remove it from the table
});
});
答案 0 :(得分:1)
$(document).ready(function () {
$("#addbutton").click(function () {
var uniqueid = $("#textbox1").val();
var text = $("#textbox2").val();
$("<tr id=" + uniqueid + "><td>row content</td> </tr>").html(text).appendTo("#table1");
// instead of value add an id | tr does not have a value!
});
$("#removebutton").click(function () {
var uniqueid = $("#textbox1").val();
$('#' + uniqueid).remove(); // use id to delete row with the same id
});
});
答案 1 :(得分:0)
<强> JSFIDDLE DEMO 强>
$("#removebutton").click(function(){
var uniqueid = $("#textbox1").val();
$('#' + uniqueid).remove();
//I want to find row with uniqueid, and remove from table
});