I have problems with this code: I can't get the value of textbox there:
here's my codes:
$(document).ready(function () {
$('#btnsave').click(function () {
//saveData();
// for looping the tr id:
$("tr#mytr", "#mytable").each(function () {
// how to get value of pos_x in every tr??
});
})
});
and here is the html
<table style="width:100%" id="mytable">
<tr id="mytr">
<td>
X position:
</td>
<td>
<input id="xPositionField" name="pos_x" style="width:100%"/>
<input id="yPositionField" name="pos_y" style="width:100%"/>
</td>
</tr>
<tr id="mytr">
<td>
Y position:
</td>
<td>
<input id="xPositionField" name="pos_x" style="width:100%"/>
<input id="yPositionField" name="pos_y" style="width:100%"/>
</td>
</tr>
<tr id="mytr">
<td>
Width:
开发者_开发问答 </td>
<td>
<input id="xPositionField" name="pos_x" style="width:100%"/>
<input id="yPositionField" name="pos_y" style="width:100%"/>
</td>
</tr>
<tr id="mytr">
<td>
Height:
</td>
<td>
<input id="xPositionField" name="pos_x" style="width:100%"/>
<input id="yPositionField" name="pos_y" style="width:100%"/>
</td>
</tr>
<tr id="mytr">
<td>
Last save date:
</td>
<td>
<input id="xPositionField" name="pos_x" style="width:100%"/>
<input id="yPositionField" name="pos_y" style="width:100%"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="btnsave" value="Save" id="btnsave" >
</td>
</tr>
</table>
in this code, i use same id of tr and some id of every textbox...
$('input[name="pos_x"]').each(function(){
var pos_x = $(this).val();
//Do what you want from here...
});
should do what you want. The reason your code doesn't work properly as written is multiple elements have the same ID. IDs should be unique (classes can be given to more than one element).
$(this).children("#xPositionField").val();
jquery cheat sheet http://labs.impulsestudios.ca/jquery-cheat-sheet
btw I think you should use a different id for the pos_y-fields (like yPositionField)
$(this).find("#xPositionField").val()
精彩评论