0

我试图在选择特定选项值时使隐藏的文本框可见,当有多个选项可用时它显然有效,因为它响应 onChange。如果这是唯一的选项,我如何让它工作,我的示例中的第一个选择框。

Js 小提琴 - http://jsfiddle.net/8bm9R/

这是我的 Js 函数

function showOther(fieldObj, otherFieldID) {
    var fieldValue = fieldObj.options[fieldObj.selectedIndex].value;
    var otherFieldObj = document.getElementById(otherFieldID);
    otherFieldObj.style.visibility = (fieldValue == 'other') ? '' : 'hidden';
    return;
} 
4

2 回答 2

2

我已经更新了 JsFiddle:

基本上 JsFiddle 被滥用,该函数应该设置为包裹在标头中而不是“onLoad”中。

jsfiddle.net/8bm9R/2/

function showOther(fieldObj, otherFieldID)
{

    var fieldValue = fieldObj.options[fieldObj.selectedIndex].value;
    var otherFieldObj = document.getElementById(otherFieldID);

    otherFieldObj.style.visibility = (fieldValue=='other') ? '' : 'hidden';

    return;
}

干杯

于 2013-06-25T07:44:40.927 回答
0
$("select").change(function() {
if($(this).val() == "expected_value") {
otherFieldObj.style.visibility = "visible"
}
else {
otherFieldObj.style.visibility = "hidden"
}
});
于 2013-06-25T07:44:38.403 回答