Home  >  Article  >  Web Front-end  >  How to make jQuery add the value in the click drop-down box to the text box

How to make jQuery add the value in the click drop-down box to the text box

php中世界最好的语言
php中世界最好的语言Original
2017-12-31 11:34:451922browse

What I bring to you this time isjQueryHow to make the value in the click drop-down box accumulate to the text box. This article will give you a good analysis.

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=&#39;&#39;;
  $("#add_subject").on("click",function(){
    seleVal+=$("#s2>option:selected").val()+&#39;,&#39;;
    $("#subject").val(seleVal);
  })
</script>
</body>
</html>

I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to the php Chinese website Other related articles!

Related reading:

How can JS click to jump to the logged-in personal mailbox

About HTTP/2 server push

nvm’s method of managing different versions of nodes

The above is the detailed content of How to make jQuery add the value in the click drop-down box to the text box. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn