jQuery的attr函数只能运行一次 [英] jquery's attr function works only one time

查看:269
本文介绍了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天全站免登陆