jquery选择器学习

阿超 发表于 2009-11-20 17:02 | 来源: | 阅读 304 次
$("img").removeAttr("title");//移除指定元素属性值

$("p:last").addClass("lastp");//addclass 为指定元素添加class,p:last 为最后一个p元素

$("p:first").addClass('firstp');//同上,只不过是第一个p元素

$("p:last").removeClass();//移除指定元素class

$("p").toggleClass("highlight");//为指定元素

$("p").toggle(function(){//toggle() 为指定元素按click轮换执行两个函数

   $(this).addClass("hignlight");

},function(){

   $(this).removeClass('hignlight');

});

$("p").click(function(){//html()为指定元素追加内容

   var html = $("p").text();

   $("p").html(html);

})

$("div").eq(1).addClass("hignlight");//第二个div关联css类别

$("div").text($("img").attr("title"));//为指定元素标签设置内容,text()用法

var text = $("div").text();//获取所有div标签元素内容

var text = $("div.d1").text();//获取指定class为d1的div标签元素内容

$("p > a").hide();//隐藏p元素内的子链接,不包括孙链接
$("p a").hide();//隐藏p元素内的所有子链接,包括子、孙链接

$("p[@a]").hide();//隐藏属性中含有a属性的p标记

$("p:eq(0)").hide();//隐藏第一个p标记

$("div:visible").hide();//隐藏所有可见div

$("p:lt(5)").css('border','2px solid')//:lt(n) 索引小于n的元素

$("p:gt(2)").css('border','7px solid green')//:gt(n) 索引大于n的元素

$("p:parent").css('background','red');

$("div:contains('tt')").hide();//隐藏所有text包行tt的div元素

$("div:contains('ccc')").css('border','3px dotted');//添加calss为所有text包行ccc的div元素

$("input:text").css('border','2px solid');//input元素下text类添加class

$("input:text",'myform').css('border','3px solid');

$("input[@type]")//属性含type的所有input元素

$("input[@type=text]").val("change input type text1");//属性为type属性值为text的所有input元素

$("input[@type=radio]").val("change input type text1");//属性为type属性值为radio的所有input元素

$("img[@src*=sina]").css('border','4px solid');//获取src属性中包含sina字符的img元素的所有元素

$("img[@src^=http]").css('color','red');//获取src属性中包口 http 字符开始img元素的所有元素

$("img[@src$=gif]").css('background','green');//获取src属性中 gif 结束字符的img元素的所有元素
关键字:
喜欢Java豆技术站点的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

*

* 绝不会泄露



返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明 | 模板设计