Jquery函数在firebug控制台中工作,但在页面中不起作用

jquery function works in the firebug console but not in the page

本文关键字:不起作用 工作 firebug 控制台 Jquery 函数      更新时间:2023-09-26

我有以下jquery函数

$("#photographers_password_confirm").focusout(function() { 
alert('bla') 
if( $("#photographers_password") != $("photographers_password_confirm") ){
                    $("#photographers_password_error").slideDown();
            }else{
                    $("#photographers_password_error").hide();
            }   
});

它在firebug控制台中工作得很好,但是当我把它放在页面中时,它无法工作,但它也没有在firebug控制台中返回任何错误。我做错了什么?

在页面中,您是"inline"运行它,作为HTML下载的一部分,还是在文档完成下载后运行它?

我的猜测是代码运行正常,但它是在HTML准备好被操作之前运行的。

确保它在$(function() { /* place code here */ });

try this:

$("#photographers_password_error").slideUp();
$("#photographers_password_confirm").focusout(function() {
    alert('bla');
    if ($("#photographers_password").val() != $("#photographers_password_confirm").val()) {
        $("#photographers_password_error").slideDown();
    } else {
        $("#photographers_password_error").slideUp();
    }
});

如果这是确切的代码,那么请在警报后加上;。有些浏览器接受它,有些浏览器不接受,所以遵循相同的旧编码风格会很好:)

相关文章: