2
function otherShow() {
    var textarea = document.getElementById("hideme");
    var x = document.forms.myForm.other_trade.value;
    if (x == "other") {
        textarea.style.display = 'block';
    }else {
        textarea.style.display = 'none';
    }
}

这是我的 JavaScript 代码,它应该隐藏包含ID=hideme和触发操作的文本区域onchange="otherShow();"

<select name="trade" required="required" class="inputbox" id="trade" onchange="otherShow();">
<option value="" selected="selected"> Select one... </option>
<option value="" disabled="disabled">  ----------------------   </option>
<option value="General Labourer">Option1</option> 
.......
</select>

上面是Select,下面是Textarea

<textarea cols="36" rows="6" class="inputbox" id="hideme" name="other_trade"></textarea>

在选择结束时,我有一个

<option value="Other"> Other </other> 

我想在选择其他时显示文本区域。请帮助我认为 loginc 是正确的,但是当我将其更改为某个值时它不起作用,它会隐藏文本区域,但不要更改它...

4

3 回答 3

1

选择框的名称trade不是other_trade

var x = document.forms.myForm.trade.value;

或者 :

var x = this.value;

代替 :

var x = document.forms.myForm.other_trade.value;
于 2012-08-20T11:55:15.217 回答
1

这是我会怎么做

window.onload=function() {
  document.getElementById("trade").onchange=function() {
    var textarea = this.form.other_trade;
    textarea.style.display=(this.value=="Other")?"block":"none";
  }
}
于 2012-08-20T11:59:29.407 回答
1

在您的 javascript 显示/隐藏条件中将other替换为Other,因为它比较区分大小写

于 2012-08-20T12:10:13.673 回答