我试图将无序列表中的文本与我通过抓取字符串中的内容然后解析它创建的数组进行比较。我似乎无法让我的 jQuery 代码的比较部分在我检查字符串是否位于数组中的地方工作。有什么建议么?
HTML
<span id="Subjects">Commercial Law & Contracts, Immigration Law, International Law & Trade, Products Liability</span>
<ul id="SubjectList">
<li>Administrative Law</li>
<li>Agriculture Updates</li>
<li>Alternative Dispute Resolution</li>
<li>Antitrust & Trade Regulation</li>
<li>Commercial Law & Contracts</li>
<li>Immigration Law</li>
<li>International Law & Trade</li>
<li>Products Liability</li>
</ul>
jQuery 代码
var subject_passed = $('#Subjects').text();
var subjectArray = new Array();
subjectArray = subject_passed.split(',');
$('#SubjectList li').each(function(){
if ($.inArray($(this).text(), subjectArray) != -1) {
alert('hello');
}
});