jQuery不适用于按钮事件

维纳亚克
var myVar;
        function colorChanger() {
                myVar = setInterval(function() { 
                var r,g,b,shadow,bottom,top;
                r = Math.floor((Math.random() * 253 ) + 1);
                g = Math.floor((Math.random() * 253 ) + 1);
                b = Math.floor((Math.random() * 253 ) + 1);
                shadow = Math.floor((Math.random() * 20 ) + 5);
                bottom = Math.floor((Math.random() * 80 ) + 1);
                    bbottom = Math.floor((Math.random() * 80 ) + 7);
                    ttop = Math.floor((Math.random() * 180 ) + 6);
                top = Math.floor((Math.random() * 200 ) + 9);
                size = (Math.random() * 100 ) + 10;
                   /* $("*").css("box-shadow",""+top+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"),0 "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),0 "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")"); */
                    $("#startinterval").css("bottom","50%");
                    $("#startinterval").css("top",ttop+"px");
                document.getElementById("123").style.color = "rgba("+r+","+g+","+b+",0.3)";   
                document.getElementById("123").style.textShadow = top+"px "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px "+bottom+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+top+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+(-top)+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")";
                    document.getElementById("123").style.textShadow = top+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px 0 "+shadow+"px rgb("+r+","+g+","+g+"),0 "+(-bottom)+"px "+shadow+"px rgb("+b+","+g+","+b+"),0 "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")",top+"px "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px "+bottom+"px "+shadow+"px rgb("+g+","+r+","+b+"),"+top+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+(-top)+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")";
                document.getElementById("13").style.backgroundColor = "rgba("+b+","+r+","+g+",0.2)";
                document.getElementById("13").style.bottom = bottom+"%";
                document.getElementById("13").style.top = top+"%";
                document.getElementById("choosen").innerHTML = "rgb("+r+","+g+","+b+")";
                $("button").click(function() {
                    $("button").css({"border-radius":bottom+"px"});
                });
            }, 20);
        }

HTML代码:

    <div align="center">
      <h2 style="font-weight: 900;font-size: 40px, -webkit-animation-delay: 5s;"><p id="123">Random Text</p></h2>
<button class="btn btn-info" onclick="colorChanger()" id="startinterval">start Animation</button>
<button onclick="stopColor()">stop Animation</button> 
      </div>

我最近开始使用jQuery,如果这是一个la脚的问题,我真的很抱歉。在上面的代码中,单击按钮时,应该将按钮的半径更改为“可变”值,但是它不起作用。我尝试使用className,element-id,但是没有运气。任何帮助将不胜感激。谢谢你。

Anamika Shrivastava

对于按钮上的触发点击事件,您必须在下面添加行

    $("button").trigger( "click" );
    $("button").click(function() {
                    $("button").css({"border-radius":bottom+"px"});
                });

这将触发按钮上的click事件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章