[英]disabling a tag with input type=button
So, I have an tag that looks like: 所以,我有一个标签,看起来像:
<a id="createBtn" class="btn" title="" type="button">
<b>+</b>
Create New
</a>
Sometimes, we want it active, sometimes not. 有时,我们希望它处于活动状态,有时则不是。 I've tried multiple ways to disable it, adding the disabled class, adding the property disabled, attempting to remove the type attribute (which I learned you cannot do), binding it to a function that prevents the default behavior, and using jquery's .bind('click', false)
, but nothing seems to work. 我尝试了多种禁用它的方法,添加了禁用的类,添加了禁用的属性,尝试删除type属性(据我所知您无法做到),将其绑定到防止默认行为的函数,以及使用jquery的.bind('click', false)
,但似乎无济于事。
I was wondering what js or jquery things I can to do this tag in order to disable it. 我想知道可以禁用此标记的哪些js或jquery东西。 It gets grayed out like it's disabled, but it still has the action tied to it which is a backbone 它像被禁用一样变灰,但它仍然具有与之相关的动作,这是一个支柱
Here's some, not all of the things that I tried: 这是我尝试过的一些方法,而不是全部方法:
this.$('#createBtn').addClass('disabled');
this.$('#createBtn').attr('type', 'button');
this.$('#createBtn').bind('click', false);
} else {
this.$('#createBtn').removeAttr('type');
this.$('#createBtn').removeClass('disabled');
The #createBtn is tied to an event that updates the UI that is created in the initialize method of this backbone view. #createBtn绑定到一个事件,该事件更新在此主干视图的initialize方法中创建的UI。
"click #createBtn": "renderNewTemplate",
This is how I go about disabling anchor
tags ( <a>
): 这就是我禁用anchor
标记( <a>
)的方法:
Disable the tag by removing its href
attribute, and decreasing its opacity
for an added effect: 通过删除标签的href
属性并降低其opacity
来禁用标签,从而增加效果:
$(document).ready(function(){
$("#createBtn").click(function () {
$(this).fadeTo("fast", .5).removeAttr("href");
});
});
And enabling the anchor: 并启用锚点:
$(document).ready(function(){
$("#createBtn").click(function () {
$(this).fadeIn("fast").attr("href", "original href here");
});
});
Original answer can be found here - I'm just recycling it as I use this in all of my projects that requires a disabling of an anchor tag 原始答案可以在这里找到-我只是在回收它,因为我在所有需要禁用锚标签的项目中都使用了它
How to enable or disable an anchor using jQuery? 如何使用jQuery启用或禁用锚点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.