jQuery 错误:太多递归
我正在使用这个水印插件用于 jQuery。它在每个页面上都运行良好,除了我的注册,它被调用了 4 次。在注册页面上,我在 jQuery(托管在 Google 上的一个)的第 57 行收到太多递归错误。我不认为 jQuery 是问题所在,尽管我认为这与我的代码或插件有关。你能看一下是否看到了什么吗?
代码:
$(document).ready(function(){
$(".text").addClass("idleField");
$(".text").focus(function(){
$(this).removeClass("idleField");
$(this).addClass("focusField");
});
$(".text").blur(function(){
$(this).removeClass("focusField");
$(this).addClass("idleField");
});
$("#recaptcha_response_field").attr("tabindex","5");
<?php if(!is_ie()){ ?>
$("#username").watermark("Desired Username");
$("#password").watermark("Password between 6 and 12 characters");
$("#confirmPassword").watermark("Confirm Password");
$("#email").watermark("Please insert a valid email");
<?php } ?>
$("#checkUser").click(function(){
$("#results").html("<img src='images/loading.gif' alt='loading...' />loading...");
var user = $("#username").attr("value");
$.get("library/regUserCheck.php", {name: user}, function(data){
$("#results").html(data);
});
});
<?php if($error){ //Make error fade out ?>
$("#errorField").delay(5000).fadeOut(1250);
<?php } ?>
});
I'm using this watermark plugin for jQuery. It works fine on every page except for my registration where it gets called 4 times. On the registration page I am getting a too much recursion error on line 57 of jQuery (one hosted on Google). I don't think it's jQuery that is the problem, though I think it has to do with my code or that plugin. Can you look to see if you see anything?
Code:
$(document).ready(function(){
$(".text").addClass("idleField");
$(".text").focus(function(){
$(this).removeClass("idleField");
$(this).addClass("focusField");
});
$(".text").blur(function(){
$(this).removeClass("focusField");
$(this).addClass("idleField");
});
$("#recaptcha_response_field").attr("tabindex","5");
<?php if(!is_ie()){ ?>
$("#username").watermark("Desired Username");
$("#password").watermark("Password between 6 and 12 characters");
$("#confirmPassword").watermark("Confirm Password");
$("#email").watermark("Please insert a valid email");
<?php } ?>
$("#checkUser").click(function(){
$("#results").html("<img src='images/loading.gif' alt='loading...' />loading...");
var user = $("#username").attr("value");
$.get("library/regUserCheck.php", {name: user}, function(data){
$("#results").html(data);
});
});
<?php if($error){ //Make error fade out ?>
$("#errorField").delay(5000).fadeOut(1250);
<?php } ?>
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码中有太多的递归,这对你来说没有任何意义吗?下面是改进后的代码:
提示:
/*@cc_on … */
)来处理 IE,而 PHP 则不需要这样做。如果您不能这样做,请将其缓存到变量中。示例:
例如,如果您想为某个元素指定更多 CSS 规则,这是最好的语法:
$(function() {
作为$(document).ready(function() {
) 的简写。我希望这已经足够了。:)
Too much recursion in your code, doesn't that mean anything for you? Here's the improved code:
Tips:
/*@cc_on … */
) to handle IE, no need to do that with PHP.If you can't do that, cache it to a variable. Example:
For example, if you want to specify more CSS rules for an element, this is the best syntax:
$(function() {
as a shorthand for$(document).ready(function() {
.I hope that's enough. :)
如果问题是多次调用
watermark
我会尝试使用计时器:If the problem is calling
watermark
multiple times I would try using timer: