gpt4 book ai didi

javascript - 用户控制按钮 Action

转载 作者:行者123 更新时间:2023-11-30 12:37:54 25 4
gpt4 key购买 nike

我有这个用户控件:

function Test1($)
{
this.Width;
this.Height;

this.show = function()
{
///UserCodeRegionStart:[show] (do not remove this comment.)
var buffer = "..." +
"<button onclick=\"alertfuncfora()\"> click </button>" +
"...";

this.setHtml(buffer);

...

///UserCodeRegionEnd: (do not remove this comment.)
}
///UserCodeRegionStart:[User Functions] (do not remove this comment.)

///UserCodeRegionEnd: (do not remove this comment.):
}

...

function alertfuncfora(){
alert("ola ola");
}

但是每次单击按钮时,在我关闭弹出窗口后页面都会刷新。我不想每次单击按钮时都刷新页面。我该怎么做?

最佳答案

发生这种情况是因为您的按钮可能位于 <form> 中标签。

使用 return false;以防止刷新。

像这样:

<button onclick="alertfuncfora(); return false;"> click </button>

关于javascript - 用户控制按钮 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25472761/

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