当前位置: 代码迷 >> JavaScript >> jquery 选择元素的有关问题
  详细解决方案

jquery 选择元素的有关问题

热度:103   发布时间:2012-06-18 13:23:36.0
jquery 选择元素的问题
HTML code

<dd><a href="javascript:void(0)">London</a></dd>                    
<dd><a href="javascript:void(0)">Bath</a></dd>
<dd><a href="javascript:void(0)">Bristol</a></dd>
<dd><a href="javascript:void(0)">Cornwall</a></dd>
<dd><a href="javascript:void(0)">Exeter</a></dd>
<dd><a href="javascript:void(0)">Plymouth</a></dd>


JScript code

var tcity="London";



如何选择链接文字=London的链接?

------解决方案--------------------
<dd><a href="javascript:void(0)">London</a></dd>
<dd><a href="javascript:void(0)">Bath</a></dd>
<dd><a href="javascript:void(0)">Bristol</a></dd>
<dd><a href="javascript:void(0)">Cornwall</a></dd>
<dd><a href="javascript:void(0)">Exeter</a></dd>
<dd><a href="javascript:void(0)">Plymouth</a></dd>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var tcity="London";

alert( $('a').filter(':contains('+tcity+')').html() )


</script>
  相关解决方案