问题
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.
回答1:
dialog()
moves the element you're passing to it, so that it's no longer matched by the selector. Might that be it?
回答2:
I think your running into a dual selector issue. Since your selecting:
$("#reportid_dialog_" + tokens[last_index]);
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
来源:https://stackoverflow.com/questions/3306414/jquerys-attr-function-works-only-one-time