-2

在表单输入中,我正在设置从服务器端接收的值。可以再次提交表单输入,但如果用户不更改输入,即替换输入并再次放置相同的值,则不应验证表单并提醒用户,不能再次设置相同的值.

- 谢谢

4

1 回答 1

1
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js"
        type="text/javascript"></script>
    <script>
        $(function () {
            var changeme = $('input[name=changeme]').val();
            $.validator.addMethod("mustchange", function (value, element) {
                if (value === changeme) {
                    return false;
                }
                else {
                    return true;
                }
            }, "you must change this value");
            $('form').validate({ debug: true });

        });
    </script>
</head>
<body>
    <form>
    <div id="main">
        <input name="changeme" type="text" value="My name is bob" class="mustchange" />
        <br />
        <input type="submit" />
    </div>
    </form>
</body>
</html>
于 2012-12-14T14:13:25.790 回答