JavaScript Onclick 问题
我无法让它发挥作用。将 JavaScript 直接放到 onclick 事件上效果很好,但这样不行。
JavaScript
function checkid(objDivID) {
if(this.id == 'id1') {
alert('ID is Checked')
};
}
HTML
<tr id='id". $row['id'] ."' class='rrtr' onclick=\"checkid(this.id);\">
<td class='name'>". $row['name'] ."</td>
<td class='data'>". $row['TotalResp'] ."</td>
<td class='data'>". $row['StaffCount'] ."</td>
<td class='data'><b>". number_format($row['Perc'],0) ."</b></td>
</tr>
谢谢,H.
I can't get this to work. Dropping the JavaScript directly onto the onclick event works fine, but it doesn't this way.
JavaScript
function checkid(objDivID) {
if(this.id == 'id1') {
alert('ID is Checked')
};
}
HTML
<tr id='id". $row['id'] ."' class='rrtr' onclick=\"checkid(this.id);\">
<td class='name'>". $row['name'] ."</td>
<td class='data'>". $row['TotalResp'] ."</td>
<td class='data'>". $row['StaffCount'] ."</td>
<td class='data'><b>". number_format($row['Perc'],0) ."</b></td>
</tr>
Thanks, H.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在传递函数
this.id
,但随后在函数中尝试再次引用该函数。这是行不通的。请改用参数名称。另外,HTML 中引用双引号的反斜杠可能并不真正存在,对吗?我猜你正在将该 HTML 打印为字符串。
You're passing the function
this.id
, but then in the function you try to reference that again. It won't work. Use the parameter name instead.Also the backslashes quoting the double-quotes in the HTML are probably not really there, right? You're printing that HTML as a string I presume.
您可以通过多种方式解决它,一种是调用指定
this
的函数:或者只使用传递的 id:
You can solve it by several ways, one is calling function specifying
this
:Or just use passed id:
那是因为您在错误的范围内使用
this
。将行更改为
That's because you are using
this
in the wrong scope. Change the lineto