0

META如果标签的内容包含在单词列表中,我正在尝试构建一个触发特定事件的 jQuery 函数。

我试过了:

<meta name="sun" content="a" >

<script>

$('meta[name=sun]').each(function(){
    var metacontent = $(this).attr("content");
    var list = ["a","b","c"];

if(metacontent.match(list)) { //that is wrong I guess
    console.log("hi");

}
});
</script> 

你能给我一个提示吗?

4

3 回答 3

1

你可以试试 jQuery 实用函数 $.inArray

if($.inArray(metacontent, list) >= 0) {
.....
于 2013-02-21T11:01:52.483 回答
0
function checkMeta(name, list) {
    var metacontent = $('meta[name="' + name + '"]').attr('content');

    return ($.inArray(metacontent, list) >= 0);
}

$(document).ready(function() {
    var list = ["a","b","c"];

    console.log(checkMeta('sun', list));
});
于 2013-02-21T11:02:25.327 回答
0

您可以尝试以下代码:

<meta name="sun" content="a" >

<script>

$('meta[name="sun"]').each(function(){
    var metacontent = $(this).attr("content");
    var list = ["a","b","c"];

$.each(list, function(index, elem){
var matches = metacontent.match(/elem/g);

if(matches.length > 0){
  //it contains a list character
}else{
  //no list character found inside the metacontent
}
});

});
</script> 
于 2013-02-21T11:06:08.153 回答