jquery常见操作总结
var value= $("input:radio[name='per'][checked]").val();
$("input[name='testradio']:eq(1)").attr("checked","checked");//
eq(1)表示第二个
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang='zh-CN' xml:lang='zh-CN' xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <script type="text/javascript" src="http://www.oschina.net/js/2012/jquery-1.7.1.min.js"></script> <script> $(function(){ $("#btnGetRadioValue").click(function(){ var value=$("input:radio[name='per'][checked]").val(); alert(value); }); $("#btnSetRadioValue").click(function(){ var value=$("input:radio[name='per'][checked]").val(); value=value*1-1; if(value==0) value=1; else value=0; $("input:radio[name='per']:eq("+value+")").attr("checked","checked"); }); $("#btnGetSelectValue").click(function(){ var value=$("#ddl").val(); alert(value); }); $("#btnSetSelectValue").click(function(){ var value=$("#ddl option:eq(2)").attr("selected","selected"); }); }); </script> </head> <body> 1<input type="radio" name="per" value="1"/> 2<input type="radio" name="per" value="2"/> <input type="button" value="GetRadioValue" id="btnGetRadioValue"/> <input type="button" value="SetRadioValue" id="btnSetRadioValue"/><br/> <select id="ddl"> <option value="-1">--</option> <option value="1">1</option> <option value="2">2</option> </select> <input type="button" value="GetSelectValue" id="btnGetSelectValue"/> <input type="button" value="SetSelectValue" id="btnSetSelectValue"/> </body> </html>
少侠,我看你气度不凡天赋异禀,骨骼精奇,这么帅,来了就帮推荐一把吧
我的最近更新