gpt4 book ai didi

javascript - 用javascript点击链接时如何删除链接属性?

转载 作者:行者123 更新时间:2023-11-28 21:13:19 25 4
gpt4 key购买 nike

我有一个工作代码。我想要的是,当用户单击促销代码链接时,链接属性将被删除并且将不再起作用。这是工作示例 http://jsfiddle.net/5DbN3/

<script language="javascript"> 
function toggle() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "Have a promo code?";
}
else {
ele.style.display = "block";
text.innerHTML = "Have a promo code?";
}
}
</script>

<h1>GET STARTED</h1>
<form action="http://www....." method="post" accept-charset="utf-8">
<label for="zipcode">
<h2>Enter your zip code:</h2>
</strong>
</label>
<div>
<input type="text" name="zipcode" id="zipcode" maxlength="5"/>
</div>
<label for="promocode">
<a id="displayText" href="javascript:toggle();">Have a promo code?</a>
</label>
<div id="toggleText" style="display: none">
<input type="text" name="promocode" id="promocode"/>
</div>
<div>
<input type="submit" name="zipsubmit" value="GO" />
</div>
</form>

最佳答案

我相信你想要:

.removeAttribute("href");

或者在 jQuery 中

.removeAttr("href");

工作 fiddle :

http://jsfiddle.net/5DbN3/1/

关于javascript - 用javascript点击链接时如何删除链接属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8199201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com