このような2つの入力フィールドがあります
<input type="text" class="span3" id name="name" >
<input type="text" class="span3" id name="phone" >
<div class="show-example1">
show content 1
</div>
<div class="show-example2">
show content 2
</div>
入力フィールド「名前」をクリックした後、div要素「show-example1」のみを表示したい
入力フィールド「電話」をクリックした後、div要素「show-example2」のみを表示します
このために、各入力フィールドに関連付けられた 2 つの div 要素を作成しました。
以下は、上記のアクションを実行するための私のスクリプトです
$('.show-example1').hide();
$('.show-example2').hide();
$("input[name='name']").bind("click", function(event){
$('.show-example2').hide();
$('.show-example1').show(400);
return false;
});
$("input[name='phone']").bind("click", function(event){
$('.show-example1').hide();
$('.show-example2').show(400);
return false;
});
私のスクリプトは正常に動作していますが、上記のアクションを実行するためのより良い方法を知りたいだけです。