Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $(“input[type=username]”).val()返回未定义的_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript $(“input[type=username]”).val()返回未定义的

Javascript $(“input[type=username]”).val()返回未定义的,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我正在为我的网站创建一个AJAX登录表单;然而,我在jQuery中遇到了一些我认为是错误的东西 代码示例: <!DOCTYPE html> <html> <head> <title>Log In</title> </head> <body> <div class="errors"></div> <input ty

我正在为我的网站创建一个AJAX登录表单;然而,我在jQuery中遇到了一些我认为是错误的东西

代码示例:

<!DOCTYPE html>
<html>
    <head>
        <title>Log In</title>
    </head>
    <body>
        <div class="errors"></div>
        <input type="username" placeholder="username">
        <input type="password" placeholder="password">
        <input type="submit" value="Log In">
    </body>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    <script>
        $('input[type=submit]').click(function(){
            $(".errors").load(window.location.protocol + "//" + window.location.host + "?username=" + $("input[type=username]").val() + "&password=" + $("input[type=password]").val());
            return false;
    });
    </script>
</html>

登录
$('input[type=submit]')。单击(函数(){
$(“.errors”).load(window.location.protocol+”/“+window.location.host+”?username=“++$”(“输入[type=username]”)。val()++“&password=“++$”(“输入[type=password]”)val());
返回false;
});
我知道这不是一个服务器端问题。
$(“输入[类型=用户名]”).val()的返回值是
未定义的
,而
$(“输入[类型=密码]”).val()的返回值是输入的值。

提前谢谢大家!:)

用户名
不是有效的
类型
属性值。我猜您想要的是
文本
,而这正是浏览器遇到无法识别的类型时的默认设置。因此,当代码运行时,
输入
实际上有一种类型的
文本
,而不是
用户名

有关有效的
类型
属性值的完整列表,请参阅


旁注-将jQuery版本升级到1.3.2或(最好)以上版本将解决此问题。我会尽快从您当前使用的古老的1.2.6版本中删除

见a。将jQuery的附带版本更改为1.2.6,它将记录未定义的
,正如您在问题中所说。

“用户名”
不是有效的
类型,它将被视为
“文本”

使用
name=“username”
$(“输入[name=username]”)来代替


好的,谢谢。CSS支持用户名类型。我真傻。@PatrickMurray-查看我的更新。如果您将jQuery更新到一个更新的版本,它将按照您的预期工作。我仍然强烈建议您不要将
用户名
用作
类型
值。在声明“bug”之前,首先确保您的测试用例有效。人们认为从网络上获取插件会让他们成为jQuery忍者