【问题标题】:jquery - change the title of a buttonjquery - 更改按钮的标题
【发布时间】:2010-09-08 15:07:36
【问题描述】:

我的按钮设置如下:

<button id="invOn2" style="float: left;">Item 2</button>

按钮在对话框中,我正在尝试在打开对话框时更改按钮的标题:

$('#invOn2').button( "option", "label", "shwaf");

这不起作用,怎么了?


这些建议还没有奏效,我将详细说明我在做什么的结构:

//jquery 设置

 $(function() {
      $('#invOnBox').dialog({
            autoOpen: false,
            resizable: false,
            height: 350,
            width: 300,
      });
      $('#invOnButton').click(function() {
            $('#invOn1 button').html('shwaf');
            $('#invOnBox').dialog('open');
            return false;
      });
    });

//invDialog 和内部按钮

 <div id="invOnBox" title="Inventory">
    <button id="invOn1" style="float: left;">Item 1</button>
    </div>

//invOnButton

<button id="invOnButton" style="float: left;">Inventory</button>

谢谢!

【问题讨论】:

标签: jquery button


【解决方案1】:

试试这个:

$('#invOn2 button').html('shwaf');

【讨论】:

  • 我不知道为什么这被否决了。使用 .text("shwaf") 会更好,但仍然......
  • 我发现有时候.text()不起作用,所以我用.html()
【解决方案2】:

有两件事:

这个选择器不会找到任何元素

$('#invOn1 button')

由于在 ID 为 #inv0n1 的元素中查找按钮元素很累,因此将其更改为仅 ID 选择器。

$('#invOn1')

我也会对对话框打开事件进行更改。这是因为我的对话通常是动态的。

$('#invOnBox').dialog({
        autoOpen: false,
        resizable: false,
        height: 350,
        width: 300,
        open : function () {
            $('#invOn1').html('shwaf');
        }
  });

..弗雷德里克

【讨论】:

    猜你喜欢
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2012-08-10
    相关资源
    最近更新 更多