您好如何使用emplStatus2 GORM对象选择Business的值?
<select name="emplStatus2" onchange="swapFieldsets(this.value, '#sa-email', '#sa-password')" class="form-control" id="emplStatus2">
<option value="Home">Send via Home Email</option>
<option value="Business">Send via Business Email</option>
<option value="Password">Set a password now,provide access information offline</option>
答案 0 :(得分:0)
如果您使用jquery,您可以这样做
$("#emplStatus2").val("Business")
如果您只想要javascript,我认为它是这样的:
document.getElementById("emplStatus2").options.value = "Business"
答案 1 :(得分:0)
答案 2 :(得分:0)
如果您想使用纯javascript选择项目,可以使用:
SelectOption3();
function SelectOption3() {
var sel = document.getElementById('select1');
var val = 'option3';
for(var i = 0, j = sel.options.length; i < j; ++i) {
if(sel.options[i].getAttribute("value") === val) {
sel.selectedIndex = i;
break;
}
}
}
<select id="select1">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
<option value="option5">option5</option>
</select>
答案 3 :(得分:0)
你需要这样的东西:
var test = '';
for (var i = 0; i < document.getElementById("emplStatus2").options.length; i++) {
if (document.getElementById("emplStatus2").options[i].value === 'Business') {
test = document.getElementById("emplStatus2").options[i].innerText;
}
}
alert(test);
以下是您的示例的JsFiddle:https://jsfiddle.net/p457utLL/