如何在jQuery Mobile中禁用链接按钮? [英] How to disable a link button in jQuery Mobile?

查看:65
本文介绍了如何在jQuery Mobile中禁用链接按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有jQuery 1.6.1链接按钮的jQuery Mobile Beta 1网站,如下所示:

I have a jQuery Mobile Beta 1 website with jQuery 1.6.1 link button like this:

<a id="subselection" href="#" data-role="button" data-theme="b">TEST</a>

在document.ready中设置点击事件:

And in document.ready i set the click event:

$('#subselection').livequery("click", function(){
  alert('test');
});

我想禁用这个链接按钮,我试过了

I whant to disable this "link button" and i tried

$('#subselection').button('disable')

并且该命令设置按钮样式,因为它被禁用但点击事件有效。

And that command set the button style like it is disabled but the click event works.

我也试过了

$('#subselection').prop('disabled', true);

和$('#subselection')。prop('disabled');给出了真实,但它没有被禁用。

and $('#subselection').prop('disabled'); gives true but its not disabled.

有人有个好主意。

推荐答案

a 元素没有属性已禁用。因此,定义一个不会影响您可能附加到它的任何事件处理程序。

The a element does not have a property disabled. So defining one won't affect any event handlers you may have attached to it.

示例:http://jsfiddle.net/niklasvh/n2eYS/

有关可用属性的列表,请查看 HTML5参考

For a list of available attributes, have a look at the HTML 5 reference.

要解决你的问题,你可以改为在元素中将禁用指定为数据

To solve your problem, you could instead for example assign the disabled as data in the element:

$('#subselection')。data('disabled',true);

然后在你的事件中检查它是否设置:

and then in your event check if its set:

if(!$(this).data('disabled'))

例如: http:// jsfiddle。 net / niklasvh / n2eYS / 5 /

这篇关于如何在jQuery Mobile中禁用链接按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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