jquery选项函数应该单独工作
我已经编写了这个jquery函数,并且希望单独工作jquery选项函数应该单独工作,jquery,Jquery,我已经编写了这个jquery函数,并且希望单独工作 $(function(){ $('.otherreason').hide(); $('.inqPurpose').change(function() { if($(this).find('option:selected').val() == "Other"){ $('.otherreason').show(); }else{ $('.otherrea
$(function(){
$('.otherreason').hide();
$('.inqPurpose').change(function() {
if($(this).find('option:selected').val() == "Other"){
$('.otherreason').show();
}else{
$('.otherreason').hide();
}
});
});
这个html代码在一个表单标记中重复4次,当我单击任何其他选项字段时,所有html一起工作,我希望单独工作
<select class="inqPurpose formField" name="how2" id="how2">
<option>Sales</option>
<option>Services</option>
<option>Corporate Partnership</option>
<option>Corporate Trade Show</option>
<option>Requesting Product Samples for Trade Show or Event</option>
<option>Website Feedback</option>
<option value="Other">Other (Please Specify)</option>
</select>
<input class="formField otherreason" type="text" placeholder="Other Reason" size="53" maxlength="300" />
销售额
服务
公司合伙
企业贸易展
为展会或活动索取产品样品
网站反馈
其他(请具体说明)
如果在选择选项之后有其他原因,则可以使用.nextAll()并查找第一个otherreason类
$(function(){
$('.otherreason').hide();
$('.inqPurpose').change(function() {
if($(this).val() == "Other"){
$(this).nextAll('.otherreason:first').show();
}else{
$(this).nextAll('.otherreason:first').hide();
}
});
});
fiddle demo在这里对于所有投票人,我相信这并不能解决问题:)亲爱的,它工作得很好,非常感谢Anton伟大的代表们每对
。inqPurpose
和。其他原因
组合在一个共同的包装元素中?