【问题标题】:Dashboard: providing user feedback by changing button label仪表板:通过更改按钮标签提供用户反馈
【发布时间】:2010-12-21 13:38:47
【问题描述】:

我想要的是通过按钮标签向用户提供有关操作状态的反馈。 最初按钮显示“保存”,单击后我想将标签更改为“保存...”进入另一个函数,一旦函数返回,将标签更改为“保存”,然后暂停 2 秒并再次将标签设置为初始“保存”值。

代码如下:

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";
}

问题在于,由于某种原因,实际上只有最后一个 document.getElementById("button").object.textElement.color = "save"; 在画布上可见,因为画布或按钮只有在我退出 myClickHandler 函数时才会呈现。 有什么提示吗?
提前致谢

【问题讨论】:

    标签: javascript dashboard dashcode


    【解决方案1】:

    这样的事情可能会更好。我很确定 setTimeout 是非阻塞的。

    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;
    }
    

    【讨论】:

    • 谢谢,它可以工作(到目前为止,我必须在生产小部件上测试它),我只需要使用 document.getElementById("button").object.textElement.innerText = labelText;而不是 document.getElementById("button").object.textElement.color = labelText; .color 是我的错字,抱歉。
    • 是的,它确实有效,现已测试。很遗憾我不明白它为什么会起作用,但我想这会随着时间的推移而到来。再次感谢 Zsolt
    • 您的原始代码阻止了浏览器并且不允许它呈现。您的所有通话都是同步的。但是 setTimeout() 是异步的,所以可以边执行边渲染。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    相关资源
    最近更新 更多