javascript - 几秒后切换 JavaScript OnClick 函数

标签 javascript jquery html onclick

在我的提交按钮上,我有 onclick="list_activity(); 但如何才能使 list_activity(); 函数在按钮按下后大约 2 秒运行点击而不是直接点击?

我正在使用的 HTML 代码:

<textarea name="blab_field" id="blab_field" style="width:98%;height:55px;" placeholder="What is on your mind?  - What are you doing right now? - Tag people with @username (username can be found on profiles)"></textarea>

          <input name="mem_id" id="mem_id" type="hidden" value="4" />
          <input name="poster_id" id="poster_id" type="hidden" value="<?php echo $logOptions_id; ?>" />
          <input type="hidden" name="type" id="type" value="a" />
          <input type="hidden" name="device" id="device" value="Google Chrome : Windows 7" />
           <input name="submit" type="submit" style="width:100%;" onClick="post_chat();" class="btn btn-info" value="Post Blab" />

最佳答案

$('input[type=submit]').on('click', function(){
     setTimeout(list_activity, 2000);                    
}});

更新:

HTML:

<input name="submit" type="submit" style="width:100%;" onClick="post_chat();" class="btn btn-info" value="Post Blab" />

JS:

  <script type="text/javascript">
    function post_chat() {
        setTimeout(list_activity, 2000); 
            //your todos
    }

    function list_activity() {
        //your todos 
    }
    </script>

关于javascript - 几秒后切换 JavaScript OnClick 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17788473/

相关文章:

php - 如何在php中制作一个滚动条来显示所有获取的视频

javascript - 使用 jquery mobile 加载页面后更新数据主题

html - 在表格单元格 div 中打断单词

javascript - 拉入本地 html 内容的 AngularJS bootstrap-ui 选项卡

c# - jquery mvc4 中的对象不支持此属性

php - HTML - 格式化垂直表格

javascript - WebView 中的 Phaser 3

javascript - 拦截javascript中对象的方法

javascript - 像 React 中的 Bootstrap 模态行为

javascript - jQuery 事件委托(delegate)