使用禁用按钮创建Jquery UI对话框

时间:2017-10-23 02:14:15

标签: javascript jquery jquery-ui

我想知道是否有一种方法可以打开禁用按钮(灰显)的对话框。

$("#battleWindow").dialog({//open battling window
    title: "Battle!",
    closeOnEscape: false,
    modal: true,
    width: 500,
    buttons:[{
        text: "Cast", //creates the button
        click: function(){
            $('#battleLog').text("You cast cure!");
        }
    },
    {
        text: "Item",//creates the botton
        click: function(){
            $('#battleLog').text("You use a potion!");
        }
    },
    {
        text: "Flee",//creates the botton
        click: function(){
            $(this).dialog("close");
        }
    }]
});

1 个答案:

答案 0 :(得分:2)

是的,您可以通过将disabled:true,添加到button(s)属性来停用按钮,如下例所示。



$(function() {
  $("#battleWindow").dialog({ //open battling window
    title: "Battle!",
    closeOnEscape: false,
    modal: true,
    width: 500,
    buttons: [{
        text: "Cast", //creates the button
        disabled: true,
        click: function() {
          $('#battleLog').text("You cast cure!");
        }
      },
      {
        text: "Item", //creates the botton
        click: function() {
          $('#battleLog').text("You use a potion!");
        }
      },
      {
        text: "Flee", //creates the botton
        click: function() {
          $(this).dialog("close");
        }
      }
    ]
  });
});

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="battleWindow"></div>
<hr/>
<div id="battleLog">Log</div>
&#13;
&#13;
&#13;

如果您对上述源代码有任何疑问,请在下面留言,我会尽快给您回复。

我希望这会有所帮助。快乐的编码!