我在Javascript中使用getCurrentPosition方法。我想实现一个按钮,当点击它时停止执行方法“getCurrentPosition”。我试图用throw/try/catch块,但它似乎没有工作:停止执行getCurrentPosition方法
try { $('#cancel').on("click", function() { $.mobile.loading('hide'); throw "stop"; }); navigator.geolocation.getCurrentPosition(foundLocation, noLocation, {enableHighAccuracy: true, timeout : 30000 }); } catch (er) { alert(er); return false; }
任何想法?在JS中甚至可能吗? 我有一个想法,但我不知道是否有可能用JS方法触发超时,以便getCurrentPosition打破?
这应该是一个异步方法,所以不应该停止渲染或任何东西,但W3规范没有让你停止启动一次。如果按钮被点击,你只是想忽略结果?你发布的代码没有工作机会,事件和异步方法不能这样工作。 – mattmanser 2013-04-11 15:16:49
单击按钮时,我想停止执行getCurrentPosition(类似于clearTimeout)。 – Laila 2013-04-11 15:20:41