Assign the value in the input box to the drop-down box

When the cursor removal or carriage return event is triggered

Assign the value in the input box to the layui drop-down box, the drop-down box is dynamically assigned, remember to refresh layui.form.render('select');

<form class="layui-form layui-col-space5" id="search_menu">
    //下拉框
	<div class="layui-inline layui-show-xs-block" style="width: 160px;">
		<select name="part" lay-filter="part" lay-search autocomplete="off" class="layui-select" id="part">
			<option value=" ">料号</option>
		</select>
	</div>

	//输入框
	<div class="layui-inline layui-show-xs-block">
		<input type="text" name="part2"  placeholder="料号" autocomplete="off" 
			  class="layui-input" value="" id="part2" onchange="change_sort(this)" οnkeypress="change_sort(this)">
	</div>
</form>
//js代码

function change_sort(that){
    //获取的料号输入框中的值
    var sort = $(that).val();

/*  //获取到料号下拉框中选中的值
    var myselect = document.getElementById('part');
    var index = myselect.selectedIndex;
    var value = myselect.options[index].value; */

    if(sort!=null){
        var options="";
        options+='<option value="'+sort+'">'+sort+'</option>'
        layui.jquery('#search_menu :input[name="part"]').html(options);
        layui.form.render('select');
    }
}

 

Guess you like

Origin blog.csdn.net/qie_wei/article/details/112883365