日期:2014-05-16  浏览次数:20993 次

ajax取值问题
$("form").serialize() 表单里面有两个input 我只想拿到第一个的input的值 怎么搞啊 求指导 


------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
    var str = $("#f").serialize();
    ar = str.split('&');
    alert(ar[0]); //t1=123
});
</script>
</head>

<body>
<form id="f">
    <input type="text" name="t1" value="123" />
    <input type="radio" name="r1" value="abc" />
</form>
</body>
</html>