Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 添加和删除输入框_Jquery_Css - Fatal编程技术网

Jquery 添加和删除输入框

Jquery 添加和删除输入框,jquery,css,Jquery,Css,我试图添加和删除一个输入框的基础上,当一个框被勾选。 然而,我似乎有一些问题。我不确定的一点是如何将$this(div)与其他属性链接起来 HTML: 生命周期秒数 寿命千字节 JavaScript: $(“#输入1,#输入2”)。单击(函数(){ 如果($(“此:选中”).length){ $(本)。在('')之后; }否则{ $(“此输入”).remove(); } }); JSFiddle: 谢谢,$(函数(){ $(function() { $('input:checkbox'

我试图添加和删除一个输入框的基础上,当一个框被勾选。 然而,我似乎有一些问题。我不确定的一点是如何将$this(div)与其他属性链接起来

HTML:


生命周期秒数
寿命千字节
JavaScript:

$(“#输入1,#输入2”)。单击(函数(){
如果($(“此:选中”).length){
$(本)。在('')之后;
}否则{
$(“此输入”).remove();
}
});
JSFiddle:

谢谢,

$(函数(){
$(function() {
  $('input:checkbox').on('change', function() {
    if ( this.checked ) {
        $(this).after('<input type="text" name="input" id="inputbox"  />');
    } else {
        $(this).next('input').remove();
    }
  });
});
$('input:checkbox')。在('change',function()上{ 如果(选中此项){ $(本)。在('')之后; }否则{ $(this.next('input').remove(); } }); });
修复了两个问题。。见下文

$(function() {
    $('input:checkbox').change(function() {        
        if ($(this).is(':checked')) {
            $(this).after('<input type="text" name="input" id="inputbox"  />');
        } else {
            $(this).next('input').remove();
        }
    });
});
$(函数(){
$('input:checkbox').change(function(){
如果($(this).is(':checked')){
$(本)。在('')之后;
}否则{
$(this.next('input').remove();
}
});
});
$(“#秒,#kb”)。单击(函数(){
$this=$(this);
如果($this.attr('checked')){
$this.after(“”);
}否则{
$('#inputbox')。删除();
}
});

可以在这里找到一种实现方法:。

最好将代码粘贴到问题中。是否需要引用$(此)?不,只是不需要在该问题上打两次电话给jq。。。通常对我的jq对象执行此操作
$(function() {
  $('input:checkbox').on('change', function() {
    if ( this.checked ) {
        $(this).after('<input type="text" name="input" id="inputbox"  />');
    } else {
        $(this).next('input').remove();
    }
  });
});
$(function() {
    $('input:checkbox').change(function() {        
        if ($(this).is(':checked')) {
            $(this).after('<input type="text" name="input" id="inputbox"  />');
        } else {
            $(this).next('input').remove();
        }
    });
});
$("#sec,#kb").click(function() {
    $this = $(this);

if ( $this.attr('checked')) {

    $this.after('<input type="text" name="input" id="inputbox"  />');

} else {

    $('#inputbox').remove();

}
});