I am facing a problem in the jquery click event. actually i was append some tr in table. my code is given below.
<table id="tblList">
<thead>
<tr><th>Country Name</th>
<th>CityName</th></tr>
</thead>
<tbody></tbody>
</table>
var rowsCount = $("#tblList tbody").find("tr").length;
var table = "<tr><td>" + countryName + "</td><td>" + cityName + "</td></tr><tr><td colspan= 2 ><div id= divGridRow ><input type= button value= add Zip Code id= btn" + rowsCount + " class= gridButton /></div></td></tr>";
$( #tblList ).append(table);
上面的代码运行正常 。 现在当点击我的 < strong > addZipCode < / strong > 按钮时, 我想显示对话框 。
我写在代码下 以获得按钮ID。
$("#tblList tbody").bind( click , function() {
$(this).find("tr").bind( click , function() {
$(this).find("input").bind( click , function() {
console.log($(this).attr("id"));
});
});
});
but still not successful to get button id 100%. In the above code i have face one more issue. if i click first time on button, no value display in console.log, when click third time,then only one time BUTTON ID is display btn0 and when i click fourth time then button id is display three time btn0 btn0 btn0 and when i click fifth time then button id is display 6 time atones like this btn0 btn0 btn0 btn0 btn0 btn0
i append multiple rows in table, and every button in row have a unique id like btn0, btn1,btn2..... simple i want to try to get button id on click.
麻烦你帮我找到解决办法,多谢夸奖
please check your self in jsfilddle http://jsfiddle.net/umairnoor84/y25LW/