Jquery表单选择器和each
来源:互联网 发布:淘宝上不能买彩票了吗 编辑:程序博客网 时间:2024/06/06 05:23
<script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $("div[id]").click(function(){//选取有id属性的div alert($(this).text()); }); $("div[title=aaa]").css("background","red"); //设置title属性为aaa的背景为红色 $("input[name=ck]").css("background","yellow");//设置input 中name是ck的背景颜色 $(":input").css("background","red");//设置所有 input背景颜色:text,所有文本 }); $(function(){//$("div").text()会做为一个字符串返回,要怎么样让他们一个一个弹出呢使用each $("div").each(function(){ alert($(this).text()); }); }); </script>
<div id="d1">22222222</div><div title="aaa">55555</div><form id="form1"><input type="radio" name="ck"/>数学<br /><input id="Radio1" type="radio" name="ck" />语言<br /><input type="radio" name="ck"/>英文<br /><input type="radio" name="ck"/>地理<br /><input type="radio" name="ck"/>化学<br /><input type="radio" name="zy"/>成功学<br /></form>