-1

点击登陆页面上的大按钮。然后点击“医学院”

然后你会看到一个表单弹出。我用“必填”类标记了很多字段(例如名字、姓氏等),但即使这些字段留空,表单仍会提交。

(1) 你能帮我弄清楚当必填字段留空时如何防止表单提交,以及 - (2) 当必填字段留空时,该字段应该变成红色,或者有一个红色边界。(我不想显示错误消息文本,因为它会使我的表单看起来更混乱。)

这是我的代码:

HTML(这只是其中的一部分):

    <input type="text" name="entry.384987407" id="entry_384987407" placeholder="First" class="ss-q-short required" />

    <input type="text" name="entry.290934326" id="entry_290934326" placeholder="Last" class="ss-q-short required" />

    <br />

    <label class="ss-q-item-label uniform">
    Email</label>
    <input type="email" name="entry.1440270198" id="entry_1440270198"         placeholder="Email" class="ss-q-short required" />

    </div>


    <div id="optional-form">
    Optional form goes here
    </div>

脚本:

    <script type="text/javascript">

    $(function(){
    $("#ss-form").validate({

   errorPlacement: function(){
        return true;  // suppresses error message text
    },
    submitHandler: function() { 

         $('#required-form').fadeOut("slow", function () {
      $('#optional-form').fadeIn("slow");
          });

         $("#entry_384987407").keyup(function () {
        var firstnameMD = $(entry_384987407).val();
    var lastnameMD = $(entry_290934326).val();
    var emailMD = $(entry_1440270198).val();

        $(".guysname").text(firstnameMD);

        }).keyup();


         form.submit(); // this MUST be AFTER everything else!!!!
         } //end of what happens when a VALID form is submitted (submitHandler)

     }); // end of function validate
     }); //end of general function


    </script>

提前致谢!!!!!!!

4

1 回答 1

0

替换此代码

$('#required-form').fadeOut("slow", function () {
    $('#optional-form').fadeIn("slow");
});

$('#required-form').fadeOut("slow");
$('#optional-form').fadeIn("slow");

并替换这个

var firstnameMD = $(entry_384987407).val();
var lastnameMD = $(entry_290934326).val();
var emailMD = $(entry_1440270198).val();

var firstnameMD = $('#entry_384987407').val();
var lastnameMD = $('#entry_290934326').val();
var emailMD = $('#entry_1440270198').val();
于 2013-07-15T06:04:00.053 回答