jquery-如何在onclick时检测元素值?
如何将 tr 值带入 .click 事件? 我希望能够将 tr id 传递到 Updatedb.php 中 - 对于 sql 更新,
输入
<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.jeditable.mini.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var global= ""
$('.click').click(function() {
var $this = $(this);
var $tr = $this.closest('tr');
alert($tr.attr('id'));
global= $tr.attr('id');
});
$('.click').editable('updatedb.php?test=123', {
indicator : "<img src='indicator.gif'>",
tooltip : "Click to edit...",
onblur : 'submit',
style : "inherit"
});
});
</script>
</head>
<body>
<tr id=1>
<td>
<span class="click" style="display: inline">Funny click here testing!</span>
<br />
</td>
</tr>
<tr id=2>
<td>
<span class="click" style="display: inline">Second inline!</span>
</td>
<tr>
</body>
</html>
请在此处
嗨,jeditable 没有后继者。 我终于设法将价值纳入全球范围。 但现在面临另一个问题。 Jeditable 不允许我传递额外的值...
我尝试过 可编辑('updatedb.php?test=123' 然后回显“开始”。 $_POST['测试'] 。 “END”
我也尝试过其他方法,但不起作用。
how do i bring the tr value into .click event?
i want to be able to pass the tr id into updatedb.php as well- for sql updating
enter
<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.jeditable.mini.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var global= ""
$('.click').click(function() {
var $this = $(this);
var $tr = $this.closest('tr');
alert($tr.attr('id'));
global= $tr.attr('id');
});
$('.click').editable('updatedb.php?test=123', {
indicator : "<img src='indicator.gif'>",
tooltip : "Click to edit...",
onblur : 'submit',
style : "inherit"
});
});
</script>
</head>
<body>
<tr id=1>
<td>
<span class="click" style="display: inline">Funny click here testing!</span>
<br />
</td>
</tr>
<tr id=2>
<td>
<span class="click" style="display: inline">Second inline!</span>
</td>
<tr>
</body>
</html>
here
Hi, jeditable don't have successor. I finally manage to get the value into global. But now facing another issue. Jeditable doesn't allow me to pass in extra value...
I tried
editable('updatedb.php?test=123'
then echo "START" . $_POST['test'] . "END"
I also tried other way, not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想查看 jQuery 插件 jEditable,它是 editable 的后继者。
链接:http://www.appelsiini.net/projects/jeditable
回到你的问题,您可以通过使用parent()、closest()或parents()请求属性来获取示例中TR节点的id。 我建议不要使用parent(),因为它希望您像示例中一样保留HTML 嵌套。 最好将parents() 或closest() 与过滤器一起使用。
You may want to check out the jQuery plugin jEditable, the successor to editable.
Link: http://www.appelsiini.net/projects/jeditable
Back to your question, you can get the id of the TR node in your example by asking for the attribute using either parent(), closest() or parents(). I'd recommend against parent() because it expects you to leave the HTML nested exactly like in your example. Better to use parents() or closest() with a filter.