JQuery:显示具有特定标题的元素
我试图仅显示将 title 属性传递给函数的元素:
var selectservice = function(serviceStr) {
$j("li.project").hide();
$j("li.project.attr('title').contains(serviceStr)").show();
};
我不太确定如何将 title 属性与传递的字符串 serviceStr 进行比较?包含似乎不起作用。
I am trying to show only elements that have the title attribute passed to the function:
var selectservice = function(serviceStr) {
$j("li.project").hide();
$j("li.project.attr('title').contains(serviceStr)").show();
};
I am not quite sure how to compare the title attribute to the passed string serviceStr? contains doesnt seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用属性等于选择器,如下所示:
请注意,属性还有其他选项同样,不仅仅是等于,例如包含、结尾为、开头为等。 参见此处查看完整列表。
Use the attribute equals selector, like this:
Note that there are other options for attributes as well, not just equals, like contains, ends with, starts with, etc. See here for a full list.