Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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
Javascript 在文本框中组合两个选择标记值_Javascript_Html - Fatal编程技术网

Javascript 在文本框中组合两个选择标记值

Javascript 在文本框中组合两个选择标记值,javascript,html,Javascript,Html,我有两个选择标签和一个文本框 <select name="select1"> <option>1</option> <option>2</option> </select> <select name="select2"> <option>1</option> <option>2</option> </select> <i

我有两个选择标签和一个文本框

<select name="select1">
   <option>1</option>
   <option>2</option>
</select>

<select name="select2">
   <option>1</option>
   <option>2</option>
</select>

<input type="number" name="text box">

1.
2.
1.
2.
我想在单击按钮时在文本框中显示两个选择标记(select1和select2)的值。提前谢谢

试试这个

var combineBtn=document.getElementById(“combine”);
combineBtn.addEventListener(“单击”,函数(){
var select1=document.getElementById(“select1”);
var select2=document.getElementById(“select2”);
var valueSelect1=select1.options[select1.selectedIndex].text;
var valueSelect2=select2.options[select2.selectedIndex].text;
document.getElementById(“text”).value=valueSelect1+valueSelect2;
});

1.
2.
1.
2.

合并
以防需要jQuery版本:)


1.
2.
1.
2.
点击我
函数combine(){
$('#text1').val($('#select1').val()+$('#select2').val())
}

您自己有没有尝试过?请把你尝试过的代码贴出来你自己做了什么?