+ -
当前位置:首页 → 问答吧 → jquery选择器

jquery选择器

时间:2009-04-26

来源:互联网

复制代码
  1. <div id="list">
  2. <ul>
  3. <li><strong>姓别</strong>:男</li>
  4. </ul>
  5. </div>
  6. 我要鼠标移动到LI上时为LI加一个类,但不包括(strong里的内容)
  7. 这要怎么写。

请各位帮帮忙。。。。谢谢~~~~~

作者: 自然   发布时间: 2009-04-26

不知合不合适
<style type="text/css">
.my{color:red}


</style>
<script type="text/javascript" language="javascript" >

  $(document).ready(function (){
  $("#list ul li").addClass("my").contents().not("[nodeType=3]").attr("style","color:black");
  });

</script>

作者: seekarmor   发布时间: 2009-04-26

复制代码
  1. 不是这样吧,
  2. <script type="text/javascript">
  3. $(document).ready(function(){
  4. $("#list ul li:not([strong])").hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});                          
  5. });
  6. </script>
  7. 像这样的,但我这代码不对,选择不了

作者: 自然   发布时间: 2009-04-26

引用
引用第2楼自然于2009-04-26 19:27发表的 :
[code]不是这样吧,
<script type="text/javascript">
$(document).ready(function(){
$("#list ul li:not([strong])").hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});                          
});
.......

晕。。。。。。。
$("#list ul li:not([strong])")
这个选择器写法明显是错误的

作者: seekarmor   发布时间: 2009-04-26

你直接给strong加个style样式不就得了,这样给li加class样式,也不会影响到strong
<li><strong  style="color:red">姓别</strong>:男</li>

作者: seekarmor   发布时间: 2009-04-26

思路错了
应该li用一个样式
然后strong再用另外一个样式覆盖li的样式
html早就不鼓励使用strong标签

作者: gordianyuan   发布时间: 2009-04-27

相关阅读 更多

热门下载

更多