JavaScript .not忽略参数

时间:2016-05-31 17:37:45

标签: javascript jquery

我想验证除文件上传器输入之外的所有输入。如果我使用.not($( "#uploader" )),它会忽略我写下的任何内容。

HTML:

<section>
        <div id="formularDiv" class="sampleFormStyle">
            <div class="wrapper">
                <h2><?php echo 'You\'re applaying for '.strtoupper($_GET['page']);?></h2>
                <form id="formularID">
                    <input id="firstName" name="firstName" type="text" placeholder="First Name:"/>
                    <input id="lastName" name="lastName" type="text" placeholder="Last Name:"/>
                    <input id="street" name="street" type="text" placeholder="Street:"/>
                    <input id="postalCode" name="postalCode" type="text" placeholder="Postal Code: " />
                    <input id="place" name="place" type="text" placeholder="Place: "/>
                    <input id="telefone" name="telefone" type="text" placeholder="Telefone: " />
                    <input id="email" name="email" type="email  " placeholder="Email: "/>
                    <textarea></textarea>
                    <label id="uploader" for="uploadFile"><i class="fa fa-cloud-upload fa-2x fa-fw" aria-hidden="true">Upload</i></label>
                    <input id="uploadFile" name="uploadFile" type="file"/>
                    <input id="submitForm" name="submitForm" type="submit" value="Submit"/>
                </form>
            </div>
        </div>
    </section> 

JavaScript的:

$('#formularID').submit(function() {
            $(":input").not('#uploader').each(function(){
                 //some code that's working without .not()
            });
})

我感谢你的每一次帮助!

2 个答案:

答案 0 :(得分:1)

试试这个。根据你的html,你想忽略的输入的id是uploadFile not uploader

$('#formularID').submit(function() {
            $("input:not(#uploadFile)").each(function(){
                 //some code that's working without .not()
            });
    })

答案 1 :(得分:0)

尝试使用jquery的<.filter()

$( "input" ).filter(function( index ) {
    return $( this ).attr( "id" ) != "uploadFile";
}).each(function(){
    // your code
});