jquery:追加div只有一次'点击' [英] Jquery: Append div only once 'on click'

查看:367
本文介绍了jquery:追加div只有一次'点击'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过点击一个按钮来追加部分 div

I am trying to append a section to a div on the click of a button.

我希望仅在第一次点击时附加部分,我在下面使用的代码附加了 section ,每次点击 div

I want the section to be appended only on the first click, the code that I use below appends a section every time I click the div.

我应该如何去做这件事?

How should I go about this?

$("#nextractorapply").click(function () {
    $("#main").append('<section id="nextractor" class="five"> </section>');  
});


推荐答案

您可以使用 one ),只触发一次

You could use one(), which fires only once

$("#nextractorapply").one('click', function () { 
    // executes only once

     $("#main").append('<section id="nextractor" class="five"> </section>');  
});

$("#nextractorapply").on('click', function () { 
    // executes every time

    // do other stuff
});

这篇关于jquery:追加div只有一次'点击'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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