是否可以通过使用href添加新元素并同时禁用href? 所以href只点击一次,之后会出现新元素。 我写了这段代码,但仍然没有运气
JS
$(document).ready(function() { $("#add_app").click(function() { $("#box").append("<p>jQuery is Amazing...</p>"); this.removeAttribute('href');this.className='disabled'; }});HTML
<a href="#" id="add_app" ><strong>Summon new element and disable me</strong></a>唯一的工作是JS系列
$("#box").append("<p>jQuery is Amazing...</p>");需要帮助..谢谢
-------------------------------------- UPDATE ----------- ---------------------- - 使用PacMan,Linus Aronsson和guest271314改进的代码,它就像一个魅力。 所以基本上我们使用.one()事件处理程序来解决问题。 谢谢你们的反馈
Is it posible to add new element with javascript by using href and disable href at the same time? So href only clicked once, and after that the new element will appear. I wrote this code, but still no luck
JS
$(document).ready(function() { $("#add_app").click(function() { $("#box").append("<p>jQuery is Amazing...</p>"); this.removeAttribute('href');this.className='disabled'; }});HTML
<a href="#" id="add_app" ><strong>Summon new element and disable me</strong></a>The only does the job is in JS line
$("#box").append("<p>jQuery is Amazing...</p>");Need help.. Thanks
--------------------------------------UPDATE--------------------------------- -Using improved code by PacMan, Linus Aronsson, and guest271314 and it works like a charm. So basically we use .one() event handler to solve the problem. Thanks for the feedback guys
最满意答案
使用这个jQuery:
$(document).ready(function() { $("#add_app").one("click", function() { $("#box").append("<p>jQuery is Amazing...</p>"); this.removeAttribute('href'); }); });我正在使用.one()事件处理程序来指示您只希望click事件发生一次。 其余的代码或多或少是正确的,只有一些小的改动。
这是一个小提琴: https : //jsfiddle.net/0mobshpr/1/
Use this jQuery:
$(document).ready(function() { $("#add_app").one("click", function() { $("#box").append("<p>jQuery is Amazing...</p>"); this.removeAttribute('href'); }); });I'm using the .one() event handler to indicate that you only want the click event to take place once. The rest of the code was more or less correct with a few small changes.
Here's a fiddle: https://jsfiddle.net/0mobshpr/1/
更多推荐
发布评论