jquery serialize 无法获取值

菜鸟快飞 2014-02-22 11:02:23
先贴代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jeasyui/jquery.min.js" charset=UTF-8></script>
<script type="text/javascript" src="jeasyui/jquery.easyui.min.js" charset=UTF-8></script>
<link rel="stylesheet" href="jeasyui/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" href="jeasyui/themes/icon.css" type="text/css"></link>
<script type="text/javascript" src="jeasyui/locale/easyui-lang-zh_CN.js" charset=UTF-8></script>
<script type="text/javascript" charset=UTF-8>
$(function(){
$("#login").dialog({
modal:true,
closable: false,
buttons:[
{
text:"登陆",
handler:function(){
console.info($('#frm').serialize());//序列化form
$.ajax({
type: "POST",
cache:false,
dataType:'json',
url:"student.do?method=login",
data:{
user:$('#user').val(),
psw:$('#psw').val()
},
success: function(msg){
$.messager.alert('标题', "Data Saved: " + msg.msg );
}
})
}
},
{
text:"重置",
handler:function(){
$('#user').val('');
$('#psw').val('');
}
}]
});
})
</script>
</head>
<body>
<div id="login" title="用户登陆" style="width:350px;height:200px;top:150px;">
<form id="frm" method="post">
<table style="margin-top:20px;">
<tr>
<th>用户名:</th>
<td><input id="user"></td>
</tr>
<tr>
<th>密码:</th>
<td><input id="psw" type="password" ></td>
</tr>
</table>
</form>
</div>
</body>
</html>


console.info($('#frm').serialize()); 这里获取不到表单的值,求各位大神解答下
...全文
783 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
緣木求魚 2016-11-16
  • 打赏
  • 举报
回复
引用 1 楼 u011461314 的回复:
<input id="user"> <input id="psw" type="password" > 把name属性写上。 <input id="user" name='xxxx'>
正解,就是这个原因。。。。
a610120310 2016-10-17
  • 打赏
  • 举报
回复
把id 改成 name serialize()获取的form表中name值
冰糖-雪梨 2014-05-12
  • 打赏
  • 举报
回复
引用 1 楼 u011461314 的回复:
<input id="user"> <input id="psw" type="password" > 把name属性写上。 <input id="user" name='xxxx'>
++
zhjdg 2014-02-22
  • 打赏
  • 举报
回复
<input id="user"> <input id="psw" type="password" > 把name属性写上。 <input id="user" name='xxxx'>

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧