美文网首页
jquery常用

jquery常用

作者: 上海第一撸码少年 | 来源:发表于2017-08-29 15:41 被阅读0次

改变css
function changeColor2(a){
$(a).siblings().css('backgroundColor','#fff');
$(a).siblings().css('color','#F6442C');
$(a).css('backgroundColor','#F6442C');
$(a).css('color','#fff');
}
改变属性
$("button").click(function(){
$("img").attr("width","180");
});

html(),val(),text()
html(), 相当于 innerHTML
text(), 相当于 innerTEXT
val() 只有有value属性的才能取到值
1.<input type='text' value='xxx'/> 这个就需要用 val()。
$("button").click(function(){
$(":text").val("Hello World");
});
2.<span>你好</span> 这个就用 text()。
$(".btn1").click(function(){
$("p").text("Hello world!");}
3.<div><p>您好!</p></div> 这个就用html()。
$('.add-twenty').on('click',function(){
$(".text_box").val(20);}

相关文章

网友评论

      本文标题:jquery常用

      本文链接:https://www.haomeiwen.com/subject/cuvodxtx.html