我有这个由 php 代码生成的 HTML 代码
<tr class="edit_tr">
<td>a1</td>
<td class="edit_td">
<span id=" " class="text"></span>
<input id="144" class="25" type="text" value="">
</td>
<td class="edit_td">
<span id=" " class="text"></span>
<input id="144" class="26" type="text" value="">
</td>
<td class="edit_td">
<span id=" " class="text"></span>
<input id="144" class="27" type="text" value="">
</td>
</tr>
这是我正在使用的 Javascript:
$(document).ready(function(e) {
$(".edit_tr").click(function(){
var id = $(this).attr("id");
// we have here tow states :#1 and #2
//#1 there is no Id, and thats mean we want to insert to database
if(typeof id == 'undefined'){
$(this).children("td").children("input").change(function(){
var stateId = $(this).attr("class");
var alternativeId = $(this).attr("id");
alert("state is :"+ stateId);
alert("alternativeId is :"+ alternativeId);
//return false;
});
}
//#2 there is an id, so we want to update the value
else{
alert("there is id ");
}
});
});
当我第一次更改输入值时的问题它工作正常,但是当我尝试再次更改值时,更改事件会触发多次
请任何帮助,我很感激