代码如下 | 复制代码 |
<html> <head> <title>chat</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <script src="/ajax/jQuery/jquery-1.8.0.js"></script> </head> <body> <form name="yys" action="aaa()"> <input type="text" name="name" value="mingzi"/> <input type="text" name="age" value="nianling"/> <input type="text" name="sex" value="xingbie"/> <input type="checkbox" id="cc1" name="cc1" value="123" checked="checked" /> <input type="checkbox" name="cc2" value="456" checked="checked" /> <input type="checkbox" name="cc3" value="789" checked="checked" /> <input type="radio" name="radio1" value="9090" /> <input type="radio" name="radio1" value="8181" /> <input type="button" name="cc2" value="123a" /> <input type="hidden" name="cc3" value="453d" /> </form> <div id="js"></div> <input type="button" onClick="getFormParameter('yys')" value=""/> </body> <script type="text/javascript" > function getFormParameter(formName){ var formParameter=""; $("form[name="+formName+"] input[type!='button'] ").each(function(){ if($(this).attr('type') =="checkbox"){ if($(this).attr('checked')) formParameter +=$(this).attr('name') + "=" +$(this).val()+"&"; }else if ($(this).attr('type') =="radio"){ if($(this).attr('checked')) formParameter += $(this).attr('name') + "=" + $(this).val()+"&"; }else{ formParameter += $(this).attr('name') + "=" + $(this).val()+"&"; } }); console.debug(formParameter); alert(formParameter); } </script> </html> |
时间: 2024-10-13 21:26:07