开发者

Select data from text fields in table using jQuery

开发者 https://www.devze.com 2023-03-15 07:01 出处:网络
I have a table as below; <table id=\"mytable\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td>&nbsp;</td>

I have a table as below;

<table id="mytable" cellpadding="0" cellspacing="0">
<tr>
<td>&nbsp;</td>
<td><input type="text" name="qwer"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="asddf"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="zxcv"></td>
<td>&nbsp;</td>
</t开发者_如何学Pythonr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="poiu"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="lkjh"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3"> <button id="BUT">BUT</button> </td>
</tr>
</table>

The middle cells contain text fields with names. I want to get data (I think .val()) from specific input fields. How can I get them? Say I want to alert value we enter in input name="zxcv".

You can see my Fiddle here.

How can I do this?


try this

$('#mytable input[name=zxcv]').val()


If you want to iterate on input fields, and show "name" and "value" when "BUT" is clicked :

$("#BUT").click(function() {
    $("#mytable input").each(function() {
        alert("name : " + $(this).attr('name') + " - value : " + $(this).val());
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号