javascript - 我怎样才能让一个按钮有一个 :active state for 1 second?

标签 javascript html css

我有这个代码:

 document.getElementById("aButton").click();

有什么办法可以让这个按钮保持事件状态一秒钟。代码有效,但没有反馈表明按钮已被点击。

请注意,我没有使用 JQuery。

最佳答案

它没有设置“事件”状态,但您可以使用 :focus 伪选择器为按钮定义 CSS 规则,然后设置 focus(),然后在超时后使用 blur():

var btn = document.getElementById('click');
btn.onclick = function() {
    var testBtn = document.getElementById('testBtn');
    testBtn.focus();
    window.setTimeout(function() {
        testBtn.blur();        
    },1000);
};

fiddle :http://jsfiddle.net/g0hyfgwg/

关于javascript - 我怎样才能让一个按钮有一个 :active state for 1 second?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29014483/

相关文章:

javascript - 更新 HTML 对象数据

javascript - WordPress Divi 主题 - anchor 链接打开特定选项卡切换

mysql - HTTP 状态 500 - "The server encountered an internal error () that prevented it from fulfilling this request"

javascript - 即使一切正常,If 语句仍无法正常工作

jquery - 未应用最大高度响应

javascript - 如何对再次保存对象数组的对象数组进行排序

javascript - 从json中提取信息

javascript - ChartJS 中雷达图的highlightFill

javascript - 向每个容器加载一定数量的元素

html - 幻灯片/旋转木马和背景 img