Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果第二次单击按钮,页面将刷新-如何防止这种情况?_Javascript_Html_Jquery Mobile - Fatal编程技术网

Javascript 如果第二次单击按钮,页面将刷新-如何防止这种情况?

Javascript 如果第二次单击按钮,页面将刷新-如何防止这种情况?,javascript,html,jquery-mobile,Javascript,Html,Jquery Mobile,我有一个按钮test。单击后,两个标签,selectedZone和selectedLocation将设置为两个虚拟值。 当第一次单击按钮时,此功能可以正常工作。但是,在第一次单击后,页面将刷新,并且不会设置标签 <!DOCTYPE html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initi

我有一个按钮
test
。单击后,两个标签,
selectedZone
selectedLocation
将设置为两个虚拟值。 当第一次单击按钮时,此功能可以正常工作。但是,在第一次单击后,页面将刷新,并且不会设置标签

<!DOCTYPE html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="language" content="en" />

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.js"></script>

        <script>
            function test()
            {
                //alert("in test fn");
                document.getElementById("selectedZone").innerHTML="ZONE TEST";
                document.getElementById("selectedLocation").innerHTML="LOCATION TEST";
            }
        </script>
    </head>

    <body>
        <button onclick="test();"> test </button>

        <br/>
        <br/>
        <label style="font-color='yellow'"> ZONE </label>
        <label id="selectedZone"></label>
        <br/>
        <br/>
        <label style="font-color='yellow'"> LOCATION </label>
        <label id="selectedLocation"></label>
    </body>

</html>

功能测试()
{
//警报(“在测试fn中”);
document.getElementById(“selectedZone”).innerHTML=“区域测试”;
document.getElementById(“selectedLocation”).innerHTML=“位置测试”;
}
试验




位置
附加说明:标记jQuery Mobile的理由:我实际上有一个弹出窗口。弹出窗口中有一个按钮。单击该按钮后,将调用相同的
test()

是否需要为标签编写额外的代码(例如:回调),以便将标签设置为与弹出窗口下拉列表中选择的值相同的值?

您缺少标题前面的html开始标记,

和。。。您在控制台中看到任何错误吗?单击后获取值。您正在刷新页面,或者页面自动刷新,可以在Chrome 25 OSX上复制。@Сааааааааа不,没有错误。@秘鲁不,我没有刷新。这就是重点。它将自动刷新,并且按钮设置的值将消失。