gpt4 book ai didi

javascript - 按钮开关盒

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:41 26 4
gpt4 key购买 nike

我似乎无法让它在 jquery 中工作。我使用此代码作为必须定义每个按钮的替代方法,但这不起作用:/

http://jsfiddle.net/pufamuf/FV4jW/1/

此外,我想知道我是否/如何对每个案例使用多个语句。谢谢:)

最佳答案

您需要在 switch 语句中的each case 之后添加一个break。更新了 JSFiddle here .

来自 Wikipedia :

break; is optional; however, it is usually needed, since otherwise code execution will continue to the body of the next case block.

Add a break statement to the end of the last case as a precautionary measure, in case additional cases are added later.

更新的 Javascript:

 $("input[type='button']").click(function() {
switch(this.id) {
case 'buttonone': $("#content").html("Content changed"); break; //notice BREAK
case 'buttontwo': $("#content").html("Content changed again"); break;
}
});

关于javascript - 按钮开关盒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6993983/

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