jquery 的 attr 函数只工作一次 [英] jquery's attr function works only one time

查看:33
本文介绍了jquery 的 attr 函数只工作一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个片段来显示一个对话框.然而,这很好用:标题将仅在我第一次单击表格单元格时设置.再次重新加载页面后,标题被设置 - 一次.无止境……

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
        });
    });
)};

我使用 jQuery 1.4.2 和 jQuery-ui 1.8.2也许有人会告诉我我做错了什么.

I use jQuery 1.4.2 with jQuery-ui 1.8.2 Maybe there is somebody to tell me what I'm doing wrong.

推荐答案

dialog() 移动您传递给它的元素,使其不再与选择器匹配.可能是这样吗?

dialog() moves the element you're passing to it, so that it's no longer matched by the selector. Might that be it?

这篇关于jquery 的 attr 函数只工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆