JQ基础使用备忘技巧(一)

来源:互联网 发布:java中的restfull接口 编辑:程序博客网 时间:2024/05/16 23:50
属性过滤选择器: 
 
$("div[id]") 选择所有含有id属性的div元素 
$("input[name='content']") 选择所有的name属性等于'content'的input元素 
 
$("input[name!='content']") 选择所有的name属性不等于'content'的input元素 
 
$("input[name^='content']") 选择所有的name属性以'content'开头的input元素 
$("input[name$='content']") 选择所有的name属性以'content'结尾的input元素 
$("input[name*='content']") 选择所有的name属性包含'content'的input元素 
 

$("input[id][name$='content']") 可以使用多个属性进行联合选择,该选择器是得到所有的含有id属性并且那么属性以content结尾的元素 


jQuery中获得选中select值

第一种方式
$('#testSelect option:selected').text();//选中的文本

$('#testSelect option:selected') .val();//选中的值

$("#testSelect ").get(0).selectedIndex;//索引

 

第二种方式
$("#tesetSelect").find("option:selected").text();//选中的文本
$("#tesetSelect").find("option:selected").val();//选中的值
$("#tesetSelect").find("option:selected").get(0).selectedIndex;//索引


设置select 选中项

1. $("#select_id ").get(0).selectedIndex=1;  //设置Select索引值为1的项选中
2. $("#select_id ").val(4);   // 设置Select的Value值为4的项选中
3. $("#select_id option[text='jQuery']").attr("selected", true);   //设置Select的Text值为jQuery的项选中
1 0
原创粉丝点击