1

使用后如何不触发以下表单的验证

javascript: form.action

我有 2 个提交按钮,第一个必须sellitem1.php用作操作,而不是使用 JQuery VALIDATION,但第二个必须 VALIDATE 表单并使用 Form Action: 中列出的操作upload.php

第二个按钮运行良好:)

<form method="post" name="UploadForm" id="UploadForm"
action="upload.php" enctype="multipart/form-data" >

<input  type="text" class="button_date"  name="price" id="price"
value="" size="15" />

<input class="button2" style="border-right:none; font-size:13px;"
name="Back" id="Back" type="submit"  value="Back" onclick="javascript:
form.action='sellitem1.php';"/>

<input class="button2" style="border-right:none; font-size:13px;"
name="List Item" id="submit" type="submit" value="List Item"
onClick="removeFocus()"/> </form>


<script>

$( "#UploadForm" ).validate({
       errorLabelContainer: "#messageBox",   wrapper: "td",
       rules: {  price: {
    required: true,
    number: true,
    range: [1.00, 500000.00]

    }   } }); </script>
4

1 回答 1

0

像下面这样的东西应该可以工作。所以基本上你会在你想要运行验证的按钮上调用validate()on事件。click

// Javascript

$('#Back').click(function (evt) {
    $('#UploadForm').attr('action', 'sellitem1.php');
});

$('#submit').click(function (evt) {
    removeFocus();
    return $("#UploadForm").validate({
        errorLabelContainer: "#messageBox",
        wrapper: "td",
        rules: {
            price: {
                required: true,
                number: true,
                range: [1.00, 500000.00]
            }
        }
    });
});

最好不要内联嵌入 javascript/css 代码。您可以按如下方式更新您的 html(请注意,我只删除了您的onclick属性而不是样式):

<form method="post" name="UploadForm" id="UploadForm"
action="upload.php" enctype="multipart/form-data" >

    <input  type="text" class="button_date"  name="price" id="price"
value="" size="15" />

    <input class="button2" style="border-right:none; font-size:13px;"
name="Back" id="Back" type="submit"  value="Back" />

    <input class="button2" style="border-right:none; font-size:13px;"
name="List Item" id="submit" type="submit" value="List Item" /> 
</form>

更新:这是展示它如何工作的小提琴http://jsfiddle.net/M3LRd/

于 2013-07-26T18:00:57.100 回答