【发布时间】:2018-06-02 05:21:03
【问题描述】:
我在 html 表中的 <td> 中有一个删除按钮,并附加了一个 onclick() 函数。如何从此函数调用 ajax,即我想获取 <tr> 中的值并发布到 URL。
<script>
function deleteRow(btn) {
var row = btn.parentNode.parentNode;
id = row.cells[0].textContent;
//call ajax, pass id as data
}
</script>
<body>
<table>
<tr>
<th>Id</th>
<th>Lastname</th>
<th>Firstname</th>
<th></th>
</tr>
<tr>
<td>122</td>
<td>Jackson</td>
<td>Evans</td>
<td><button type="button" onclick="deleteRow(this)">Delete row</button></td>
</tr>
</table>
</body>
【问题讨论】:
-
你会用jQuery吗?
-
不用jQuery也可以做到
-
看起来你没有做太多研究。网上这样的例子不胜枚举。您是否尝试过发出 AJAX 请求?如果是这样,请将您的尝试添加到问题中。
-
Google 是您最好的朋友:google.com/search?q=ajax+post+request
标签: javascript