0

ユーザーがリストからアイテムを選択したときにラベルを非表示にするにはどうすればよいですか?入力テキストを非表示にするこのコードがありますが、その入力テキストのラベルを非表示にするにはどうすればよいですか?

<form name="myform">
<table>
<td>
<select name="one" onchange="if (this.selectedIndex==8){this.myform['other'].style.visibility='visible'}else {this.myform['other'].style.visibility='hidden'};">
<option value="" selected="selected">Select...</option>
<option value="1">1</option>
<option value="2">3</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="other">Other</option>
</select>
<label>Other</label><input type="textbox" name="other" style="visibility:hidden;"/>
</td>
</table>
</form>

どうすればそれができるかを隠したい<label>Other</label> ですか?

4

3 に答える 3

0

デモ

このようにドロップダウンのテキストまたは値を一致させることはできませんthis.selectedIndex

this.selectedIndex == 8インデックスに一致するように変更します

テキストボックスid="other"を表示または非表示にします。

<select name="one" onchange="if (this.selectedIndex== 8){document.getElementById('other').style.visibility='visible'}else {document.getElementById('other').style.visibility='hidden'};">

更新されたデモ

レーベルのIDを新しくしましたl_other

<select name="one" onchange="if (this.selectedIndex== 8){document.getElementById('l_other').style.visibility='visible';
document.getElementById('other').style.visibility='visible'}else {document.getElementById('l_other').style.visibility='hidden';
document.getElementById('other').style.visibility='hidden'};">

デモ

otheridラップlabeltextboxその内部で単一の div を使用する

<select name="one" onchange="if (this.selectedIndex== 8){
document.getElementById('other').style.visibility='visible'}else{
document.getElementById('other').style.visibility='hidden'}">
于 2013-08-06T04:43:36.633 に答える