jquery移动按钮自动刷新页面

发布于 2024-12-20 05:42:06 字数 486 浏览 3 评论 0原文

我使用 jquery mobile 创建一个移动网页。我定义了一个按钮和一个 onclick 事件。执行 onclick 函数后,我的页面会自动刷新。有谁知道为什么会发生这种情况或者我该如何阻止它?

我的按钮声明:

<button id="rateButton" data-theme="a" data-icon="star" data-iconpos="right" onclick="BtnRatePressed();">Rate</button>

功能:

function BtnRatePressed() {
    var rateBtn = document.getElementById('rateButton');
    rateBtn.style.visibility = 'hidden';
    alert("yeh");

}

我收到警报,然后页面刷新。

I a using jquery mobile to create a mobile web page. I defined a button and an onclick event. After the onclick function is carried out my page is automatically refreshed. Does anyone know why this is happening or how i can stop it?

my button declaration:

<button id="rateButton" data-theme="a" data-icon="star" data-iconpos="right" onclick="BtnRatePressed();">Rate</button>

function:

function BtnRatePressed() {
    var rateBtn = document.getElementById('rateButton');
    rateBtn.style.visibility = 'hidden';
    alert("yeh");

}

I receive the alert and then the page refreshes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他是夢罘是命 2024-12-27 05:42:06

我们需要代码来找出答案。您可以通过什么方式向我们提供现场演示吗?

您可能忘记在 onclick 事件结束时返回 false。忽略 false 的返回将使浏览器无论如何执行链接的 href,这可能会显示为页面重新加载。

正如我所说,查看实时示例,将 return false 添加到 或

您的 BtnRatePressed 函数

function BtnRatePressed()
{
    var rateBtn = document.getElementById('rateButton');
    rateBtn.style.visibility = 'hidden';
    alert("yeh");
    return false;
}

onclick 语句中。

<button id="rateButton" data-theme="a" data-icon="star" data-iconpos="right" onclick="BtnRatePressed(); return false;">Rate</button>

We need code for this to find out. Any way you can supply us with a live demo?

You might have forgotten to return false at the end of the onclick event. Neglecting the return of false will make the browser to execute the href of the link anyway, which might appear as a page reload.

As I stated, seeing the live example, add return false to either

your BtnRatePressed function

function BtnRatePressed()
{
    var rateBtn = document.getElementById('rateButton');
    rateBtn.style.visibility = 'hidden';
    alert("yeh");
    return false;
}

or within the onclick statement.

<button id="rateButton" data-theme="a" data-icon="star" data-iconpos="right" onclick="BtnRatePressed(); return false;">Rate</button>
↘人皮目录ツ 2024-12-27 05:42:06

return false; 添加到 BtnRatePressed() 的末尾,这样即使点击也不会传播,也不会导致表单提交。

编辑:此外,将属性更改为 onclick="return BtnRatePressed();"

Add return false; to the end of BtnRatePressed() so that the click even isn't propagated and doesn't cause the form to submit.

Edit: Also, change your attribute to onclick="return BtnRatePressed();"

分分钟 2024-12-27 05:42:06

问题是您正在使用实际的按钮,这会导致表单动作,您可以通过使用像这样的超链接按钮来完成同样的事情并避免问题......

<a href="javascript:BtnRatePressed();" data-role="button" id="rateButton" data-theme="a" data-icon="star" data-iconpos="right">Rate</a>

The problem is that you're using an actual button and that is causing the form to action, you can accomplish the same thing by using a hyperlink button like this and avoid the problem...

<a href="javascript:BtnRatePressed();" data-role="button" id="rateButton" data-theme="a" data-icon="star" data-iconpos="right">Rate</a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文