简体   繁体   English

如何删除href链接的禁用属性

[英]How to remove the disabled attribute of a href link

When I use this line 当我用这条线

$("#edit-link-1").removeAttr("href"); $( “#编辑链接-1”)removeAttr( “HREF”)。

It disables the link. 它禁用链接。

Now I want to enable the same link again. 现在,我想再次启用相同的链接。 So I tried this line, but its kind of not working :( 所以我尝试了这一行,但是它行不通:(

$("#edit-link-1").addAttr("href",true); $( “#编辑链接-1”)addAttr( “HREF”,真)。

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"> 
</script>

<a href="#" id="edit-link-1">Link1</a>
<script type="text/javascript">
    $("#edit-link-1").removeAttr("href");
    $("#edit-link-1").addAttr("href",true);
</script>

在jQuery中,添加属性的正确方法是:

$("#edit-link-1").attr("href", 'https://www.google.com/');

Also you have another option, depends on wich jQuery version are you working on. 另外,您还有另一个选择,取决于您正在使用的jQuery版本。

Since v1.6 you can use prop , http://api.jquery.com/prop/ 从v1.6开始,您可以使用prophttp://api.jquery.com/prop/

var $link = $("#edit-link-1");
$link.prop('href', 'https://www.google.com/');

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM