gpt4 book ai didi

javascript - 使用 jquery 动态获取一些 tr 值并使用 ajax 将它们传递给 php

转载 作者:行者123 更新时间:2023-11-30 18:41:45 26 4
gpt4 key购买 nike

我想在按下“删除”按钮时将一些 td 值传递给 ajax 调用我如何使用 jquery 做到这一点?

<table>
<tr>
<td class="datao">first column</td>
<td class="data1">first column</td>
<td class="data2">first column</td>
<td colspan="2"></td>
</tr>
<tr>
<td class="datao">xzczxc</td>
<td class="data1">xzczxc</td>
<td class="data2">xzczxc</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">xzczxc</td>
<td class="data1">xzczxc</td>
<td class="data2">xzczxc</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">xzczxc</td>
<td class="data1">xzczxc</td>
<td class="data2">xzczxc</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">xzczxc</td>
<td class="data1">xzczxc</td>
<td class="data2">xzczxc</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">xzczxc</td>
<td class="data1">xzczxc</td>
<td class="data2">xzczxc</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
</table>

更新:假设我想获取 's 中 input type=text 的值。

HTML 示例:

 <table>
<tr>
<td class="datao">
<select class="someclass">
<option value="asdsa">somevalue</option>
</select>
</td>
<td class="datao">
<input type="text" value="eqw" />
</td>
<td class="datao">
<input type="text" value="gfg" />
</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">
<select class="someclass">
<option value="wq">somevalue</option>
</select>
</td>
<td class="datao">
<input type="text" value="hfd" />
</td>
<td class="datao">
<input type="text" value="vcv" />
</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
<tr>
<td class="datao">
<select class="someclass">
<option value="cva">somevalue</option>
</select>
</td>
<td class="datao">
<input type="text" value="ewd" />
</td>
<td class="datao">
<input type="text" value="asad" />
</td>
<td>
<input type="button" class="deleteRow" value="Delete" />
</td>
</tr>
</table>

jquery的代码:

假设我想获取每行数据的 select 值...

$('input.deleteRow').live('click', function() {
var values = [];

$(this).closest('tr').find("select").each(function() {
values.push($(this).attr('value'));
});

//Confirm
//the ok stores true or false returned by confirm!
var ok = confirm("Are you sure...?");

//testing for true
if(ok){
$.post("phpscript.php", { someName:values[0] }, function(data) {
if(data == '1'){
alert("something");
location.reload();
}
else
alert("something else, error probably");
});
}

});

如果你想获取 select 和 input type="text"只需要做:...find("select, input[type=text]")...

这是我对社区的贡献。无论如何,我想找到一种将数据发送到 php 脚本的优雅方式,请帮帮忙。

最佳答案

可以使用http://www.datatables.net/ - 比自己编程容易多了?

关于javascript - 使用 jquery 动态获取一些 tr 值并使用 ajax 将它们传递给 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6664563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com