我有以下代码:
HTML
<head>
<meta property="article:section" content="Pop or Not" />
</head>
JS
<script>
jQuery(document).ready( function($) {
var metaSection $("meta[property='article:section']").attr("content");
if (metaSection.indexOf('Pop or Not') >= 0){
alert ('The is Pop Page!');
}
});
</script>
问题在于我认为我需要这样才能使用我定义的变量我需要将其转换为字符串。肯定会喜欢一些意见。
答案 0 :(得分:2)
如果HTML没问题,这应该可行
var metaSection = $("meta[property='article:section']").attr("content");
if (metaSection.indexOf('Pop') >= 0) {
alert('The is Pop Page!');
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
<meta property="article:section" content="Pop" />
</head>
&#13;