繁体   English   中英

jQuery:包含为选择器

[英]jQuery :contains as a selector

我正在尝试使用:contains作为选择器:

    var test = jQuery(":contains('"+content_uq_name+"')").css();
    console.log(test);

我收到jQuery错误:

TypeError: a is undefined


...eChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},...

我究竟做错了什么? 谢谢

在您发表评论后,我建议使用.each()的一种解决方案

 $("div:contains('test')").each(function() { $(this).text("test1"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>test</div> <div>car</div> <div>test</div> <div>test</div> <div>test</div> <div>test</div> 

您必须指定要替换文本的元素。

.css()需要一个参数。 api文档

控制台输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM