gpt4 book ai didi

javascript - jQuery 不适用于按钮事件

转载 作者:行者123 更新时间:2023-11-28 05:20:51 25 4
gpt4 key购买 nike

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,如果这是一个蹩脚的问题,我真的很抱歉。在上面的代码中,在单击按钮时,它应该将按钮的半径更改为“可变”值,但它不起作用。我尝试使用 className、element-id 但没有成功。任何帮助将不胜感激。谢谢。

最佳答案

要触发按钮上的点击事件,您必须添加以下行

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

这将触发按钮上的点击事件。

关于javascript - jQuery 不适用于按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39056936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com