想要根据下拉框选择来显示/隐藏div [英] Want to show/hide div based on dropdown box selection
本文介绍了想要根据下拉框选择来显示/隐藏div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只有在下拉框中选择业务用途时,我才想让jQuery显示div id ='business'。
这是我的代码:
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery。 min.js>
< / script>
< script> $('#purpose')。on('change',function(){
if(this.value =='1');
{
$( #business)。show();
}
else
{
$(#business)。hide();
}
} );
});
< / script>
< body>
< select id ='purpose'>
< option value =0>个人使用< / option>
< option value =1>商业用途< / option>
< option value =2>传递给客户端< / option>
< / select>
< div style ='display:none;'id ='business'>商家名称< br />& nbsp;
< br />& nbsp;
< input type ='text'class ='text'name ='business'value size = '20'/>
< br />
< / div>
< / body>
和JSFiddle: http://jsfiddle.net/2kGzZ/1/
解决方案
$('#purpose')。on('change',function(){
if(this.value =='1')
// ... .................. ^ .......
{
$(#business)。show();
}
else
{
$(#business)。hide();
}
});
});
将代码包装在 $(document).ready(function(){...........});
处理程序,也删除;
$(code> $(document).ready(code $> $))之后的code>如果
$('#purpose')。on('change',function(){
if(this.value =='1')
// ... .................. ^ .......
{
$(#business)。show();
}
else
{
$(#business)。hide();
}
});
});
I want to have jQuery show div id='business' only if 'business use' is selected in the dropdown box.
This is my code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$('#purpose').on('change', function() {
if ( this.value == '1');
{
$("#business").show();
}
else
{
$("#business").hide();
}
});
});
</script>
<body>
<select id='purpose'>
<option value="0">Personal use</option>
<option value="1">Business use</option>
<option value="2">Passing on to a client</option>
</select>
<div style='display:none;' id='business'>Business Name<br/>
<br/>
<input type='text' class='text' name='business' value size='20' />
<br/>
</div>
</body>
and the JSFiddle: http://jsfiddle.net/2kGzZ/1/
解决方案
Wrap the code within $(document).ready(function(){...........});
handler , also remove the ;
after if
$(document).ready(function(){
$('#purpose').on('change', function() {
if ( this.value == '1')
//.....................^.......
{
$("#business").show();
}
else
{
$("#business").hide();
}
});
});
这篇关于想要根据下拉框选择来显示/隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文