jQuery 验证的第一天,但不是 jQuery 的第一天。很简单的问题:我有三个文本输入:姓名、电话和电子邮件。我想要求姓名(没有汗水)和电话或电子邮件,并确保输入在电话或电子邮件中有效。我试过这个:
$(document).ready(function() {
$("#contactForm").validate({
debug:true,
rules: {
name: {
required: true
},
email: {
email:true,
required: function(element){
!$("#phone").valid();
}
},
phone: {
phoneUS: true,
required: function(element){
!$("#email").valid();
}
}
},
messages: {
name: "Please specify your name",
email: {
required: "Please enter a valid email"
},
phone: "Please enter a 10 digit phone number"
}
});
Run Code Online (Sandbox Code Playgroud)
});
但它失败了,因为每个有效性检查都会调用另一个,无限递归并使浏览器崩溃。
必须有一些简单的方法来做到这一点,但我已经花了将近两个小时,它逃脱了我:(
好吧,我知道这里有一些简单的东西,我想要丢失,我所要做的就是存储从jQuery查询返回的对象,如
var obj = $("#objectID");
作为一个全局vand然后从函数内引用它.
下面的示例提供了狗的图片,但随后使用jQuery交换图像的src属性以显示一只猫.我错过了什么?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- jquery -->
<script src="jquery-1.6.1.min.js" type="text/javascript" language="javascript"></script>
<!-- image swap -->
<script type="text/javascript" language="javascript">
// a global jQuery object
var globalMainImage = $("#mainImage");
// a global integer
var globalInteger = 420;
$(document).ready(function() {
/* this works
$("#mainImage").hide();
$("#mainImage").attr("src", "http://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Youngkitten.JPG/800px-Youngkitten.JPG");
$("#mainImage").fadeIn(1500);
*/
/* and this works
var localMainImage = $("#mainImage");
localMainImage.hide();
localMainImage.attr("src", "http://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Youngkitten.JPG/800px-Youngkitten.JPG");
localMainImage.fadeIn(1500);
*/
/* and this works
alert(globalInteger);
*/
/* but this …Run Code Online (Sandbox Code Playgroud) 我需要覆盖一些yii核心文件 - 特别是CGridColumn.php和CController.php.我需要确保在我的应用程序中引用这些类,而不是它们覆盖或扩展的核心文件.我该怎么做呢?它必须非常简单,但我似乎找不到记录在案的"正确"方法.