插入datepicker后,Jquery表单验证不起作用

前端之家收集整理的这篇文章主要介绍了插入datepicker后,Jquery表单验证不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想创建一个带有datepicker textfield,name,contact和bla bla bla的预订表格.

验证工作正常,而我的表单获取名称输入文本字段,电子邮件输入文本字段,联系人输入文本字段,除了日期戳.

插入jquery datepicker后,验证不起作用,并且datepicker工作正常.

有人可以帮我吗?

<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/validation.js" type="text/javascript"></script>
<script src="js/effects.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="css/style.css" />

<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.7.custom.min.js"></script>
<link type="text/css" href="css/start/jquery-ui-1.8.7.custom.css" rel="stylesheet" />
<script>
$(function() {
 $( "#datepicker" ).datepicker();
});
</script>


<form id="test" action="#" method="get">
<fieldset>
    <!--<legend>Form</legend>-->
    <div class="form-row">
        <div class="field-label">
          <label for="name-t2">*Your Name:</label>
          </div>
        <div class="field-widget"><input name="name-t2" id="name-t2" class="required" title="Enter your name" /></div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="email-t2">*Your Email:</label></div>
        <div class="field-widget"><input name="email-t2" id="email-t2" class="required validate-email" title="Enter a correct email. E.g. xx@example.com" /></div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="contact-t2">Contact Number:</label></div>
        <div class="field-widget"><input name="contact-t2" id="contact-t2" class="validate-digits" title="Enter your contact number" /></div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="datepicker">Departure Date:</label></div>
        <div class="field-label">
            <input id="datepicker" name="datepicker" class="required validate-date-au" type="text" />
        </div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="ppl-t2">Number of People:</label></div>
        <div class="field-label"><input name="ppl-t2" id="ppl-t2" class="validate-number" title="Optional: Enter number of people" /></div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="budget-t2">Your Budget:</label></div>
        <div class="field-widget">
            <select id="budget-t2" name="budget-t2" class="validate-selection" title="Choose your budget">
                <option>Select one...</option>
                <option>< $100</option>
                <option>$100 - $250</option>
                <option>$250 - $500</option>
                <option>$500 - $750</option>
                <option>$750 - $1,000</option>
                <option>> $1,000</option>
            </select>
        </div>
    </div>
    <div class="form-row">
        <div class="field-label"><label for="enquiry-t2">Special Enquiry:</label></div>
        <div class="field-label">
         <input type="checkBox" name="enquiry-t2" id="enquiry-travel" value="Travel" />Travel<br>
            <input type="checkBox" name="enquiry-t2" id="enquiry-accommadation" value="Accommodation"  />Accommodation<br>
            <input type="checkBox" name="enquiry-t2" id="enquiry-flight" value="Flight Ticket"  />Flight Ticket<br>
            <input type="checkBox" name="enquiry-t2" id="enquiry-other" value="Others" class="validate-one-required" />Others 
        </div>
    </div>

    <div class="form-row">
        <div class="field-label-textarea"><label for="comment-t2">Your Message:</label></div>
        <div class="field-label-textarea">
                <TEXTAREA NAME="comment-t2" id="comment-t2" class="required" cols=55 rows=10></TEXTAREA>
        </div>
    </div>

</fieldset>
<input type="submit" value="Submit" /> <input type="button" value="Reset" onClick="valid.reset(); return false" />
</form>

<script type="text/javascript">
 var valid2 = new Validation('test',{useTitles:true});
</script>

解决方法

你的代码的问题是你的jQuery库和原型库是冲突的.

许多JavaScript库使用’$’作为函数或变量名,就像jQuery一样.这里jquery和原型库与’$’相冲突.在jQuery的情况下,’$’只是’jQuery’的别名.要修复这个添加jquery在没有冲突模式.

jQuery.noConflict();

包括你所有的jquery代码如下:

(function($) {    

     //jquery code goes here.    

})(jQuery);

查看完整的代码

<script type="text/javascript">

jQuery.noConflict();

(function($) {  
          $("#datepicker").datepicker();
})(jQuery);

</script>

上述过程将确保jQuery与您的其他库不冲突,即本例中的原型.

猜你在找的jQuery相关文章