我使用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");

}

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

最佳答案

我们需要为此找到代码。您可以通过任何方式向我们提供实时演示吗?

您可能已经忘记在onclick事件结束时返回false。忽略返回false将使浏览器仍然执行链接的href,这可能会在页面重新加载时出现。

正如我所说,看到实时示例,将添加为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>

关于javascript - jQuery的移动按钮自动刷新页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8448658/

10-11 22:23
查看更多