Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery选项函数应该单独工作_Jquery - Fatal编程技术网

jquery选项函数应该单独工作

jquery选项函数应该单独工作,jquery,Jquery,我已经编写了这个jquery函数,并且希望单独工作 $(function(){ $('.otherreason').hide(); $('.inqPurpose').change(function() { if($(this).find('option:selected').val() == "Other"){ $('.otherreason').show(); }else{ $('.otherrea

我已经编写了这个jquery函数,并且希望单独工作

$(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
。其他原因
组合在一个共同的包装元素中?