为了账号安全,请及时绑定邮箱和手机立即绑定

求问代码为什么不能实现?

<!DOCTYPE html>
<html>
    <head>
        <title>使用$.extend()扩展工具函数</title>
       <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
        <style>
            *{
                margin:0;padding:0;
                }
            div{
                width:300px;
                margin:10px auto;
                padding:5px;
                }
            span{
                margin:10px;
            }
            li{
                list-style:none;
                margin:10px auto;
                width:100px;
                border:1px solid;
            }
        </style>
        
        <script>
           $(function () {
                $("li").each(function(index){
                    var a = $("#a").val();
                    $("li:eq(index)").hover(
                        function(){
                         $(this).css("background-color", "a");
                        },
                        function(){
                         $(this).css("background-color", "#fff");
                        })
                })
            }); 
            
        </script>
    </head>
    
    <body>
    <div>
        <span>输入颜色:</span><input type="text" id="a" >
        <ul>
            <li>1</li>
            <li>22</li>
            <li>333</li>
            <li>4444</li>
            <li>55555</li>
        </ul>
        <div id="content"></div>
    </div> 
    </body>
</html>

求问哪里错了?

正在回答

2 回答

  <script>

           $(function () {

                $("li").each(function(index){

                   

                    $("li:eq("+index+")").hover(

 

                        function(){

                 var a = $("#a").val();//look here

                         $(this).css("background-color", a);

                        },

                        function(){

                         $(this).css("background-color", "#fff");

                        })

                })

            }); 

             

        </script>


0 回复 有任何疑惑可以回复我~
$("li:eq(index)")

改成

$("li:eq("+index+")")


0 回复 有任何疑惑可以回复我~
#1

666图 提问者

改了,还是不行
2016-01-14 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
jQuery基础课程
  • 参与学习       154708    人
  • 解答问题       7289    个

加入课程学习,有效提高前端开发速度

进入课程

求问代码为什么不能实现?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号