Jos*_*son 14 javascript jquery business-logic
我需要获取content某个meta标签的属性值.
var someContent = $("meta[name=someKindOfId]").attr("content");
Run Code Online (Sandbox Code Playgroud)
我通常是这样做的.出于商业原因,someKindOfId可能会somekindofid.它也可能是其他案例组合.我不知道.
搜索此元标记的最佳方法是什么?添加id或其他标识符是不可能的.
Nic*_*tes 27
您可以像这样使用jquery过滤器函数
var meta = $('meta[name]').filter(function() {
return this.name.toLowerCase() == 'somekindofid';
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/nickywaites/mkBvC/
另外,对于不区分大小写的属性*= selector:
$("meta[name*=someKindOfId]")
Run Code Online (Sandbox Code Playgroud)
您可以使用:
$('meta').filter(function() {
return (/somekindofid/i).test($(this).attr('name'));
}).attr("content")
Run Code Online (Sandbox Code Playgroud)