我有一个 html 列表,我尝试在列表中找到一个文本等于“cat”的 span 元素
<div id= "target_language_tag_list">
<ul class="target-tag-list">
<li><span id="tag_18" class="myTag">éléphant</span></li>
<li><span id="tag_31" class="myTag">box</span></li>
<li><span id="tag_29" class="myTag">cat</span></li>
<li><span id="tag_30" class="myTag">pig</span></li>
<li><span id="tag_32" class="myTag">flower</span></li>
</ul>
我编写了以下 js.coffee 脚本,但得到了“未定义”的答案
translatedTag = $('input#tag_translated_name').val() # cat
targetList = $('#target-tag-list')
found = targetList.find("span:contains(" + translatedTagName + ")")
alert 'found: ' + found.attr('id') # should be tag_29 but is undefined
我也尝试直接测试,同样的未定义错误
found = $("#tags.tab-pane.active #target-tag-list li span:contains('cat')")
alert 'found: ' + found.attr('id') # should be tag_29 but is undefined
我想我的 contains 过滤器使用有问题,......但有什么问题?