搜索 用户中心
55分类目录网(www.hao311.com)打造品牌形象分类目录网站大全,您网站推广首选网站目录平台!

55目录

分类目录 > 新闻资讯 > 站长动态 > jQuery contains过滤器实现精确匹配使用方法

jQuery contains过滤器实现精确匹配使用方法

来源:互联网 编辑:55分类目录编辑整理 分类:新闻资讯 站长动态 日期:2018-11-01 11:01:32 浏览: 加入收藏
jQueycoais过滤器实现精确匹配使用方法 时间:2018-11-0111:03:19 浏览:1 来源:悟空seo复制代码代码如下: &l;!DOCTYPEhml&g; &l;hmlxmls=&quo;hp://www.w3.og/1999/xhml&quo;&g; &l;head&g; &l;meahp-equiv=&quo;Coe-Type&quo;coe=&quo;ex/hml;chase=u

资讯详情

jQuery contains过滤器实现精确匹配使用方法

  • 时间:
  • 浏览:1
  • 来源:悟空seo

复制代码 代码如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//根据select中的option的文本来执行选中
//$("#selectbox option[text='第二项']");
//$("#selectbox option").filter("[text='第二项']");
//上面两种写法都是错误的
//正确写法
$("#btn4").click(function () {
var $option =$("#selectbox option:contains('第二项')").map(function(){
if ($(this).text() == "第二项") {
return this;
}
});
alert($option.length > 0 ? "有对象" : "无对象");
$option.attr("selected", true);
});
});
</script>
</head>
<body>
<form id="form1">
<div>
<select id="selectbox">
<option value="1">第一项</option>
<option value="2">第二项</option>
<option value="21">第二项1</option>
</select>
<input type="button" id="btn4" value="contains测试" />
</div>
</form>
</body>
</html>

$(".selector:contains('xx')")
  contains()只作匹配查找,不够精确,包含xx的selector和包含xxabc的selector都会查到。

解决办法:
?$(".selector:contains('xx')[innerHTML='xx']")
  这样将查找内容只有xx的selector。

版权声明:

1、本文转载自互联网,如果您是文章原创作者,请联系本站注明您的版权信息。

2、55目录仅提供信息发布平台,不承担相关法律责任。

3、文章仅代表作者个人观点,不代表55目录立场,未经作者许可,不得转载。

4、如果发现本站有涉嫌抄袭的内容,欢迎举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

上一页:js实现单一html页面两套css切换代码

下一页:JQuery操作Select的Options的Bug(IE8兼容性视图模式)