Home >Web Front-end >JS Tutorial >Detailed explanation of how jQuery implements clicking the value in the drop-down box to accumulate it into the text box
This article mainly introduces jQuery's method of adding the value in the click drop-down box to the text box, involving jQuery event binding and dynamic acquisition and operation of page element attributes. Friends who need it can refer to it. I hope it can help. to everyone.
Let’s take a look at the running effect first:
The specific code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <title>www.jb51.net jQuery添加下拉框元素</title> <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script> </head> <!-- 加在body标签中屏蔽右键 oncontextmenu="return false" --> <body > <select name="city" id="s2" lay-search> <option value="">请选择</option> <option value="layer">layer</option> <option value="form">form</option> <option value="layim">layim</option> </select> <button class="layui-btn " type="button" id="add_subject">添加</button> <input name="subject" id="subject" type="text" data-label="," value=""> <script> var seleVal=''; $("#add_subject").on("click",function(){ seleVal+=$("#s2>option:selected").val()+','; $("#subject").val(seleVal); }) </script> </body> </html>
Related recommendations :
jQuery implements select drop-down box to obtain the currently selected text
jQuery custom multi-select drop-down box effect implementation method
Talk about how to use jQuery to implement custom multi-select drop-down box effects
The above is the detailed content of Detailed explanation of how jQuery implements clicking the value in the drop-down box to accumulate it into the text box. For more information, please follow other related articles on the PHP Chinese website!