小编FRE*_*TER的帖子

html()函数完成后如何运行循环?

我试图在div中写入一些文本之后运行一些javascript代码,如下所示:

<!DOCTYPE html>
<html>
    <head>
        <title>HTML Tutorial</title>
    </head>
<body>
    <button type="button" id="btnTest">Click</button>
    <div id="testDiv" style="width:100px; height: 100px; background-color: red;">
    </div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type='text/javascript'>
    $('#btnTest').on('click', function() {
        $('#testDiv').html('hello');

        for(var i=0; i<5000; i++) {
            console.log('testing');
        }
    });
</script>
</html>
Run Code Online (Sandbox Code Playgroud)

我想在单击按钮后立即在div中显示文本'hello',并且只有在此之后我才想要执行for循环.但是,仅在for循环运行时才会显示文本.

我怎么解决这个问题?

html javascript jquery

-3
推荐指数
1
解决办法
104
查看次数

标签 统计

html ×1

javascript ×1

jquery ×1