请问这段js为什么无法运行?
运行test.htm出错color_sheet.htm 中的代码如下:
<div class="color">
<div>#FFDF7A</div>
<div>#80785E</div>
<div>#4D3B00</div>
<div>#FFEDB3</div>
<div>#FFF8E1</div>
<div>#AD57B3</div>
</div>test.htm中的代码如下:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".good").load(
"color_sheet.htm",
$(".good>div").each(function(){
$(this).css({background-color: $(this).text()}); //这行报错
})
)
});

</script>
<div class="good"></div>

解决方案 »

  1.   

    jquery的问题!!!
    不懂,等待高手解答
      

  2.   

     将出错那句改为$(this).css("background-color", $(this).text());就可以了。$(this).css()有四种方法,楼主可以去查一下jquery的帮助。
      

  3.   

    $(this).css({backgroundColor: $(this).text()}); //这行报错
    $(this).css("background-color", $(this).text());//这行报错
      

  4.   


    $(this).css({"background-color": $(this).text()});//这行报错
      

  5.   


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $(".good").load(
                "color_sheet.htm",
                function(){
                    $(".color>div").each(function(){
                        $(this).css("background-color",$(this).text());
                    })
             }
            )
        });
        
    </script>
    <div class="good"></div>