2012-10-14 46 views
-2

当onClick被调用时并且在location.href启动之前,是否可以将类切换为加载图形并禁用该按钮?有一个延迟,我希望避免双击。有人可以给我看一个这样的例子吗?开关类和禁用按钮

<button type="button" class="MoreTides" onclick="location.href='http://www.domain.com/tides/parser_iphone.php?stats=$xml->stationid'">View Graph - Change Dates</button> 
+3

是... [用JavaScript更改元素的CSS类(http://stackoverflow.com/questions/195951/change-an -elements-css-class-with-javascript),[如何使用JavaScript禁用HTML按钮?](http://stackoverflow.com/questions/3014649/how-to-disable-html-button-using-javascript)在提出问题之前搜索一个好主意。 – sachleen

回答

2

像这样的东西可能是一个开始:

<script> 
    function loadPage(input) { 
    input.disabled = true; 
    input.className = "loadingButton"; // define how this should look in CSS 
    location.href='http://www.domain.com/tides/parser_iphone.php?stats=$xml->stationid'; 
    } 
</script> 

<button type="button" class="MoreTides" onclick="loadPage(this)">View Graph - Change Dates</button>