触发函数后弹出登陆注册框,但是用户输入username和password后无法通过document.getElementById读入到user和pass中。
请各位大侠赐教!
function SigninDialog(){
resetValue();
alert('in the Show Sign In Dialog function');
$dialog = $('<div></div>')
.html('<div id="dialog-confirm" title="Enter your imformation for sign in:">'+
'User: <input type="text" id="u" name="u"></input><br />'+
'Password: <input type="password" id="p" name="p"></input>'+
'</div>')
        
.dialog({
autoOpen: false,
modal: true,
title: 'Sign In',
buttons: {
'Signin': function() {
//Send Signin Request to Server
                
var user = document.getElementById("u").value;
var pass = document.getElementById("p").value;
alert(user);
alert(pass);

signin(user,pass);

$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
 
    close: function() { $(this).remove(); } 
}); $('#signin').click(function() {
$dialog.dialog('open');
// prevent the default action, e.g., following a link
return false;
});
}

解决方案 »

  1.   

    多截取了一部分

       $('#signin').click(function() {
                $dialog.dialog('open');
                // prevent the default action, e.g., following a link
                return false;
            });
        }

    望忽略
      

  2.   

    写法上没问题,只要你看得到弹出层,你说的问题应该不会发生
    用的哪个版本的jQuery?最新的应该不会有问题,我测试过的
      

  3.   


    谢谢答复!我的jQuery用的是1.4.2的。
    感觉也不是代码的问题,是其他设置上出错了吗?
      

  4.   

    这段代码是在index.jsp中的。
    错误就是最后user和pass的值为空,通过signin()传参过去,显示为空值。
    在下面这个代码段中:
    var user = document.getElementById("u").value;
    var pass = document.getElementById("p").value;
    alert(user);
    alert(pass);alert出来的user和pass已经是空的了。但之前检验了input所获得的值有不为空且为输入的值。
    所以怀疑是document.getElementById("u").value出问题了。
    但在另一个jsp中,register.jsp中也是同样写法,是可以读入值的。于是就困惑了