jquery方法混剪

1.添加和不添加readonly

$('#2_1_input11').attr("readonly","readonly");$('#2_1_input11').removeAttr("readonly")

2.radio选中和不选中

$("#rdo1").attr("checked","checked");$("#rdo1").removeAttr("checked");

判断radio是否被选中:if($('#2_3_radio1').is(':checked')){console.log('ok')}else{console.log('no')}

3.select操作

//1、设置value为pxx的项选中
$(".selector").val("pxx");
//2、设置text为pxx的项选中
$(".selector").find("option[text='pxx']").attr("selected",true);
//3、获取当前选中项的value
$(".selector").val();
//4、获取当前选中项的text
$(".selector").find("option:selected").text();
//5.选中某个option选项也是让它默认选中,
$('#demo option:eq(1)').attr('selected','selected');

 4.选择器及常用修改

$("p").width(200);
$("p").css({'color':'red','font-size':'18px;'})
$("p").animate({'width':'50px'},50)
var left = $('#test').css('left')  // 有px
var left = $('#test').position().left // 无px  js  console.log(that.offsetLeft)

children()  获取子元素
parent()  获取父元素
parents()  获取祖先元素
prev()  获取前一个兄弟元素
prevAll()  获取前面所有的兄弟元素
next() 获取后一个兄弟元素
nextAll() 获取后面所有的兄弟元素
siblings()  获取前后所有的兄弟元素
find() 获取最里层的元素;如:$("ul").find("span"),那么不管在span上加了多少层父级都会直接选上它

1.找父级里的第一个子级的第二个兄弟级
<h2 id='myForm'>
<span></span>
<span></span>
<span></span>  // 选它
<span></span>
</h2>
$('#myForm').children('span').first().next().next()

 5.好用的事件:

blur: input失去焦点

on: 当元素被循环创建可以用它来绑定事件

posted @ 2021-07-14 11:26  封兴旺  阅读(36)  评论(0编辑  收藏  举报

联系方式: 18274305123(微信同号)