jquery的attr函数只工作一次
我使用这个片段来显示一个对话框。不过,这效果很好:仅在我第一次单击表格单元格时才会设置标题。再次重新加载页面后,标题将被设置 - 一次。无穷无尽...
$(document).ready(function() {
$("td[id^='_ctl0_tbl_content_reportid_']").click(function() {
var tokens = this.id.split('_');
var last_index = tokens.length - 1;
var _dialog = $("#reportid_dialog_" + tokens[last_index]);
var _title = _dialog.attr("title");
_dialog.dialog({
modal: true,
closeText: 'Hide',
width: 450,
title: _title
});
});
)};
我使用 jQuery 1.4.2 和 jQuery-ui 1.8.2 也许有人告诉我我做错了什么。
I use this snippet to show a dialog. This works great however: the title is going to be set only for the first time I click the table cell. After reloading the page again the title is set - for one time. Ad infinitum...
$(document).ready(function() {
$("td[id^='_ctl0_tbl_content_reportid_']").click(function() {
var tokens = this.id.split('_');
var last_index = tokens.length - 1;
var _dialog = $("#reportid_dialog_" + tokens[last_index]);
var _title = _dialog.attr("title");
_dialog.dialog({
modal: true,
closeText: 'Hide',
width: 450,
title: _title
});
});
)};
I use jQuery 1.4.2 with jQuery-ui 1.8.2
Maybe there is somebody to tell me what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
dialog()
移动您传递给它的元素,以便它不再与选择器匹配。可能就是这样吗?dialog()
moves the element you're passing to it, so that it's no longer matched by the selector. Might that be it?我认为您遇到了双选择器问题。由于您的选择:
第二次单击表格单元格并调用dialog()时,有2个#reportid_dialog_实例,当您尝试设置attrs时,这会导致id冲突
I think your running into a dual selector issue. Since your selecting:
The second time you click on the table cell and call dialog() there is 2 instances of #reportid_dialog_ which would lead to id's clashing when you attempt to set attrs