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())
}
您自己有没有尝试过?请把你尝试过的代码贴出来你自己做了什么?