Dashboard: providing user feedback by changing button label
What I want is to provide user feedback about operation status through button label. Initially the button says "save", once clicked I want to change the label to "saving..." enter another function and once t开发者_运维百科he function returns change the label to "saved" then pause 2 seconds and set the label again to initial "save" value.
Here is the code:
function myClickHandler(event)
{
document.getElementById("button").object.textElement.color = "saving...";
functionx ()
document.getElementById("button").object.textElement.color = "saved";
sleep (5000);
document.getElementById("button").object.textElement.color = "save";
}
The problem is that for some reason only the last document.getElementById("button").object.textElement.color = "save";
is actually visible on canvas because the canvas or button are rendered only once I exit from myClickHandler
function.
Any hint?
Something like this might work better. I'm pretty sure setTimeout is non-blocking.
function myClickHandler(event) {
updateLabel("saving...");
setTimeout("performFunctionX()", 250);
}
function performFunctionX() {
functionx;()
updateLabel("saved");
setTimeout("updateLabel('save')", 5000);
}
function updateLabel(labelText) {
document.getElementById("button").object.textElement.color = labelText;
}
精彩评论