2

我正在尝试禁用此按钮

<a  data-role="button" id="next"  data-icon="arrow-r" >Next</a>

click 事件不应触发,并且按钮 UI 还应反映按钮禁用状态。

我试过以下

$("#next").attr('disabled',true);
$("#next").attr("disabled", "disabled");
$("#next").button('disable');
$("#next").button().button('disable');

似乎没有人同时处理这两个问题。

4

3 回答 3

3

工作示例:http: //jsfiddle.net/Gajotres/YFMsR/

不幸的是,只能禁用 INPUT 按钮,button('disable')因此您需要像这样模拟它:

$('#next').prop('disabled', true).addClass('ui-disabled');

Classui-disabled是一个用于禁用外观的 jQuery Mobile 类。

完整示例:

$(document).on('pagebeforeshow', '#index', function(){ 
    // So we can test if button is disabled or not
    $(document).on('click', '#next', function(){     
        alert('Click event');
    });    
    $('#next').prop('disabled', true).addClass('ui-disabled');
});

如果您想了解更多信息,请查看这篇文章,您会发现该主题的描述更加详细。

于 2013-05-31T11:23:12.323 回答
1

你不能禁用<a>本身。

你可以:

  • 取消导航return false;
  • 设置href#
  • 改为使用<input type="button">

如果你使用 jQuery ui 的按钮小部件,你应该使用这个:

$( "#next" ).button( "disable" );

文档

于 2013-05-31T10:44:14.593 回答
0

试试这个。它禁用导航

   $("button class").attr("disabled", "disabled");

   $('button class').css('opacity', '0.3');
于 2013-05-31T10:47:41.553 回答