Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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 insertafter()在$(此)变量中不起作用_Jquery - Fatal编程技术网

jquery insertafter()在$(此)变量中不起作用

jquery insertafter()在$(此)变量中不起作用,jquery,Jquery,jqueryinsertafter()在$(此)变量中不起作用 我的代码在这里 <select name="input_field[]" class="selectcase"> <option value="">Select</option> <option value="input">Text</option> <option value="option">Opti

jquery
insertafter()
$(此)
变量中不起作用

我的代码在这里

<select name="input_field[]" class="selectcase">
        <option value="">Select</option>    
        <option value="input">Text</option> 
        <option value="option">Option</option>  
</select>

挑选
正文
选项
剧本

$(this).change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});
$(this).change(函数(){
$(“”)之后插入($(this));
});

我有许多选择标签和选择特定的选择标签。使用更改功能,我想在选择标记后添加文本框。我使用了
insertAfter()
函数。但它不起作用。

在您的情况下,
的值将是
窗口
,因此您应该使用类名绑定事件

$('.selectcase').change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});
$('.selectcase').change(函数(){
$(“”)之后插入($(this));
});

当绑定事件
$(此)
指的是
窗口。您需要使用正确的选择器,即
$(“.selectcase”)
而不是
$(此)
来侦听
选择的更改事件

$(".selectcase").change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});
$(“.selectcase”).change(函数(){
$(“”)之后插入($(this));
});

不要使用
作为第一行中的id,必须替换为
选择

$('select').change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});
$('select').change(函数(){
$(“”)之后插入($(this));
});