1

我有一个带有这样标记的表单......

你剪了哪张优惠券

<div class="answer item1">
  <input type="checkbox" name="downloaded_vouchers[answer1]" id="answer1" value="1"/>
   <label for="answer1">Answer 1</label>
</div>
<div class="answer item1">
   <input type="checkbox" name="downloaded_vouchers[answer1]" id="answer1" value="1"/>
   <label for="answer1">Answer 1</label>
</div>

你用的是哪个代金券

 <div class="answer item1">
  <input type="checkbox" name="used_vouchers[answer1]" id="usedanswer1" value="1"/>
   <label for="answer1">Answer 1</label>
</div>
<div class="answer item1">
   <input type="checkbox" name="used_vouchers[answer1]" id="usedanswer1" value="1"/>
   <label for="answer1">Answer 1</label>
</div>

我需要能够以某种方式在提交表单时检查凭证削减是否与使用的凭证匹配,有一些验证服务器端,但我也需要做一些客户端,不知道从哪里开始,我需要直接使用javascript没有jquery或类似的,有人可以帮忙吗?

4

1 回答 1

2

像这样的东西......

   <script type="text/javascript">
    function validate( )
    {
        // use document.getElementById to get the form item
        var item = document.getElementById("yourElement");
        if ( somecondition == true )
        {
            alert("good to go");
            // allow the form to post
            return true;
        }
        else
        {
            alert("I don't think so");
            // return false so the form will not post
            return false;
        }
    }
    </script>

    <form onsubmit="Validate();" >
    </form>

从 onsubmit 方法返回 true 将发送表单,返回 false 不会

于 2009-07-30T14:50:41.817 回答