10/10/2018, 11:35

hiển thị loading khi đang xử lý

chào các bác, em đang gặp 1 rắc rối sau trong javascript:
khi click vào 1 button thì nó sẽ chạy function a. nhưng trong function a có vòng lặp chạy khoảng 800 lần và nó chạy rất lâu.
Có cách nào để trong khi đang chạy nó hiện lên dòng chữ processing... không vậy?
Mong các bác chỉ giáo
zmt264 viết 13:39 ngày 10/10/2018
Được gửi bởi danhnguyen223
Bạn tìm hiểu khái niệm Ajax nhé.

câu hỏi của chủ topic hình như ko liên quan AJAX đâu, bạn chủ topic có thể đưa code mẫu lên http://jsbin.com rồi đưa link đây mọi người sẽ giúp bạn, mình đoán là có thể dùng setTimeout
flowergreen viết 13:41 ngày 10/10/2018
cái này mình cũng chịu
it4you.vn viết 13:42 ngày 10/10/2018
Code:
<body>
       <div id="alertprocessing" style="margin:0px auto; display:none;width:200px; height:50px; border: 1px solid #CCC;text-align:center;line-height:50px;z-index:9999;">
            <span id="msg"> Prosessing ...</span>
       </div>
    
        <div>
            <input id="btn" type="button" value="click me" />
        </div>
        <script type="text/javascript">
            var c = 0;
            var t;
            function wait(bool) {
                if (bool) {
                    document,getElementById('alertprocessing'),style,position = 'absolute';
                    document,getElementById('alertprocessing'),style,top = ((window,innerHeight / 2) - 50) + 'px';
                    document,getElementById('alertprocessing'),style,left = ((window,innerWidth / 2) - 100) + 'px';
                    document,getElementById('alertprocessing'),style,display = 'block';
                }
                else {
                    document,getElementById('alertprocessing'),style,display = 'none';
                }
            }
            function a() {
                c = c + 1;
                document,getElementById('msg'),innerHTML = 'Prosessing: ' + c;
                t = setTimeout("a()", 1000);
                if (c == 20) {
                    wait(false);
                }
            }

            document,getElementById('btn'),onclick = function () {
                wait(true);
                a();
            }
        </script>
    </body>
=,= có phải như thế ? (Sửa dấu , thành dấu . dd ko cho post link mà làm gì có link chỉ có đấu . pó tay)
luuanhquyen viết 13:45 ngày 10/10/2018
thì dùng js lúc nhấn nút function thì hiển thị chữ Processing lúc xử lý xong thì bỏ đi thôi mà. Hiện thị ra % thì mới phức tạp thôi.
Bài liên quan
0