<!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>
    <title>jQuery</title>
    <script language="javascript" type="text/javascript" 
            src="Jscript/jquery-1.4.2.min.js"></script>
    <style type="text/css">
           body{font-size:12px;text-align:left}
           div{float:left;border:solid 1px #ccc;margin:8px;width:100px;height:65px;}
           span{float:left;border:solid 1px #ccc;margin:8px;width:45px;height:45px;background-color:#eee}
    </style>
    <script type="text/javascript">
function changeCSS(){
$("input[name*='test']").val("name包含'test'的").css("background-color","blue");
}


</script>
</head>
<body>
<input name="test1" value="a"/><br/><br/>
<input name="test2" value="b"/><br/><br/>
<input name="test3" value="c"/><br/><br/><p>
<button onclick="changeCSS();">test</button>&nbsp;&nbsp;&nbsp;&nbsp;</body>
</html>
用jquery,很容易实现的。

解决方案 »

  1.   

    $("input[name*='test']") --这个语句就是得到这3个input
      

  2.   

    楼主的意思是要得到[a,b,c]而不是三个input
      

  3.   

    正解,,我怎么怎么都解释不清楚呢..
    我要求的结果就是:用最简单的方法得到一个数组,里面是[a,b,c]
      

  4.   

    jquery貌似没有这样直接的方法,估计要自己写
      

  5.   

    可以这样写var arr = new Array();
    var test = $("input[name^='test']").each(function(){
       arr.push($(this).val()); 
    })
      

  6.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="JavaScript" src="/js/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    $('input[name=t]').click(function(){
                                 //获取的本来就是数组,你要获取数组的数值就需要遍历
    $("input[name*='test']").each(function(){
    alert($(this).val());
    });
    });

    });

    </script>
    </head>
    <body>

    <input type="button" name="t" value="test">
    <br>
    <input name="test1" value="a"/>
    <input name="test2" value="b"/>
    <input name="test3" value="c"/>

    </body>
    </html>
      

  7.   

    搞太麻烦了,给这三个input添加form标签在外面,给这form弄个id 选择器这个表单 serialize()方法就取出全部值
      

  8.   

    这个方法不管你有多少个input都取出来了~
      

  9.   

    请看:http://blog.sina.com.cn/s/blog_5f66526e0101egse.html
      

  10.   

    $("input [name^='name']")返回的是一个数组元素而不是jquery对象,我说的对吗?