当我选择两个值(每个多选框中有一个)时,我想更改标签的值。如box1中的option1和box2中的option2,标签值更改。
<select id="opt1" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select id="opt2" multiple="multiple">
<option value="1">Opt 1</option>
<option value="2">Opt 2</option>
<option value="3">Opt 3</option>
<option value="4">Opt 4</option>
</select><br />
<label id="changeme">This should change</label>
答案 0 :(得分:0)
答案 1 :(得分:0)
var FLAG1=0;
function update(){
if(FLAG1==0){
FLAG1=1;
}
else{
var ct=document.querySelectorAll('select');
document.getElementById('changeme').innerHTML=ct[0].value+"-"+ct[1].value;
FLAG1=0;
}
}
<select id="opt1" multiple="multiple" onchange="update();">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select id="opt2" multiple="multiple" onchange="update();">
<option value="1">Opt 1</option>
<option value="2">Opt 2</option>
<option value="3">Opt 3</option>
<option value="4">Opt 4</option>
</select><br />
<label id="changeme">This should change</label>
答案 2 :(得分:0)
你可以从这样的事情开始
var label = document.getElementById("changeme");
var opt1 = document.getElementById("opt1");
var opt2 = document.getElementById("opt2");
opt1.onchange = function() {
label.textContent = opt1.value + "-" + opt2.value;
}
opt2.onchange = function() {
label.textContent = opt1.value + "-" + opt2.value;
}