jQuery实现变色

来源:互联网 发布:mac docker lnmp 编辑:程序博客网 时间:2024/06/10 04:44
    <title></title>


    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        function backgorundColor(i) {
            //   this.document.body.style.backgroundColor = i;
            //            this.document.getElementById('div1').style.backgroundColor= i;
            this.document.getElementsByName('div').item[0].style.backgroundColor = i;
        }


        function changeColor() {
            var a = document.getElementsByName('color');
            for (var i = 0; i < a.length; i++) {
                if (allradio[i].checked == true) {
                    document.body.style.backgroundColor = a[i].value;
                }
            }
        }


//        $(function () {
//            $('input').click(function () {
//                $('body').css('background-color',$(this).attr('value'));
//            })
//        })
    </script>
</head>
<body>
<div id="div1" style="width:200px;height:200px;"></div>


  <input id="Radio1" type="radio" value="Red" name="color" onclick="backgorundColor('Red')" /> 红色
  <input id="Radio2" type="radio" value="Blue" name="color" onclick="backgorundColor('Blue')" />蓝色
  <input id="Radio3" type="radio" value="Green" name="color" onclick="backgorundColor('Green')" />绿色
  <input id="Radio4" type="radio" value="Orange" name="color" onclick="backgorundColor('Orange')" />橙色
</body>