When the layui drop-down box is pulled down, select all the values in the box

The drop-down box of layui has a search function.

Dynamically assign a value to the drop-down box, and you want to select the value when you drop it, because you don’t need to delete the value when searching, which is convenient for users to operate.

 

So I thought of making it all selected when focusing. If it is an input box, you can write it like this: <input οnfοcus="this.select();">

But here is the drop-down box, and it is the drop-down box of layui, so it doesn't work.

Press F12, you can see that the drop-down box of layui is after the select option that we dynamically wrote by ourselves, layui also generates a div...These data are placed in this div, if you directly operate on the select, it will It's just scratching the boots, and it doesn't help. You must operate on the div it generates.

I saw a picture on the Internet, which is a structure diagram of layui rendering select into div

So according to this figure, operate the input under the div generated by layui and add a οnfοcus="this.select();"

Guess and guess and finally got it right:

$("#selectCustomer").siblings("div.layui-form-select").find("div.layui-select-title").find("input").attr("onfocus","this.select()");

 

 

Guess you like

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