1

以下は私のニーズにぴったりでした。チェックボックスの状態を取り、私のために素晴らしいことをしました。チェックボックスがオンまたはオフに基づいて、3つの異なるフォーム要素を表示(表示/非表示)しました。簡単だと思います。繰り返しになりますが、コードの対称性と10行未満の場合は「単純」に基づいています。それ以外は迷ってしまいました。しかし、私はIEのチェックボックスの境界線の問題とXブラウザの配置yippeedoodlesをいじることを公式に諦めました。私はピクセルを完璧な方法で完璧にしたいと思っています。しかし、私はその戦いに負けました。しかし、それについて議論するのではなく、フォーム選択ボックスを使用して、チェックボックス(下)で実行できたのと同じことを実行する必要があります。

<form id="form">
<input id="checkbox" name="checkbox" type="checkbox" onclick="showhideid" />
</form>



#IdOne, #IdTwo, #IdThree (visibility:hidden;}


function showhideid()
{
    if (document.form.checkbox.checked)
    {   
        document.getElementById("IdOne").style.visibility = "visible";
        document.getElementById("IdTwo").style.visibility = "visible";
        document.getElementById("IdThree").style.visibility = "visible";
        document.getElementById("IdFour").setAttribute("class", "required");

    }
    else
    {
        document.getElementById("IdOne").style.visibility = "hidden";
        document.getElementById("IdTwo").style.visibility = "hidden";
        document.getElementById("IdThree").style.visibility = "hidden";   
        document.getElementById("IdFour").setAttribute("class", "");
    }
}

さて、選択ボックス(下)を使用して同じことを達成できれば、私は幸せな男を死にます。

これは私が得た限りです。私はJquery/CSSのマニュアルページを読むのがとてもめまいで、すべてをまとめることができません。

<html>

<form id="form">

<select name="SelectBox">
<option>Make a Choice</option>
<option value="Value1">Selection1</option>
<option value="Value2">Selection2</option>
<option value="Value3">Selection3</option>
</select>

<label id="IdOne" for="input1">MeAndMyInputAreInvisibleByDesign</label>
<input id="IdTwo" name="input1" type="text">

<span id="IdThree">Im Not In display:none Mode I'm In visibility:hidden Mode. Big difference."
</span>

<input id="IdFour" name="input2" type="text" class="I have none, but I will soon. I hope" />

</form>

</html>
4

2 に答える 2

3

selectタグを見てください:

<select name="SelectBox">
<option>Make a Choice</option>
<option value="IdTwo">Selection1</option> <!-- the value should be the id of the input field -->
<option value="IdThree">Selection2</option>
<option value="IdFour">Selection3</option>
</select>

ここで、表示/非表示にする各要素にセレクター クラスを与える必要があります。

<input id="IdTwo" name="input1" type="text" class="toggle">
<span id="IdThree" class="toggle">
   Im Not In display:none Mode I'm In visibility:hidden Mode. Big difference."
</span>
<input id="IdFour" name="input2" type="text" class="toggle" />

次に、JavaScript を見てください。

jQuery(document).ready(function(){
 jQuery('input[name="SelectBox"]').change(function(){
  jQuery('.toggle').css({"visibility":"hidden"});//Hide all
  jQuery("#" + jQuery(this).val()).css({"visibility":"visible"});
 });
});
于 2011-04-17T11:06:57.323 に答える
1

次のようなことができます。

<html>

<form id="form">
<input type="text" id="IdOne" class="toggle" />
<input type="text" id="IdTwo" class="toggle" />
<input type="text" id="IdThree" class="toggle" />
<select name="SelectBox" id="selectBox">
<option value="0">Make a Choice</option>
<option value="IdOne">First element</option>
<option value="IdTwo">Second element</option>
<option value="IdThree">Third element</option>
</select>

</html>

これはJavaScriptで:

jQuery(document).ready(function(){
 jQuery("#selectBox").change(function(){
  jQuery(".toggle").hide();
  jQuery("#" + jQuery(this).val()).show();
 });
});
于 2011-04-17T07:31:08.517 に答える