使用jQuery添加输入字段 [英] Add input field with jQuery

查看:96
本文介绍了使用jQuery添加输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery还是很陌生,所以仍然想尽一切办法.

I'm quite new to jQuery, so still trying to wrap my head around how it works.

我正在创建一个管理面板,管理员可以在其中插入一些问题.由于不是固定数量,因此管理员应该可以添加或删除额外的输入字段,因此管理员可以选择所需的数量问题.

I'm creating a admin-panel where the admin can insert some questions. As its not a fixed amount, the admin should be able to add or remove extra input-fields, so the admin can choose the desired amount questions.

以图形方式显示:

这是代码:

            <div class="adinputfield90">
            <input type="text" placeholder="Insert question 1"> <span class="font-entypo icon-circled-cross adaddnextremove" aria-hidden="true"></span></input>
            </div>

span类保存图像,因此添加的输入只是另一个Webfont.

The span class holds the image, so the add-new input is just another webfont.

如何使它起作用,所以我可以添加无限数量的输入字段?我应该确保如果只有一个输入,我只能添加,而不能删除该输入.

How can I get this to work, so I can add an infinite amounts of inputfields? I should of cause make sure that if theres only one input I can only add, and not remove that one.

感谢所有帮助!

推荐答案

尝试一下.

$('.adaddnextremove').on('click', function(){
    $(this).parent().clone(true).appendTo('body');
    $('.remove').show();
    $('.adaddnextremove').hide();
    $('.adinputfield90').last().find('.remove').hide();
    $('.adinputfield90').last().find('.adaddnextremove').show();
});
$('.remove').on('click', function(){
    $(this).parent().remove();
});

小提琴演示

这篇关于使用jQuery添加输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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