JQuery 記錄區

學無止境 經常忘記的技巧 記錄區
回覆文章
leeyc
文章: 81
註冊時間: 2020年 10月 23日, 01:54

JQuery 記錄區

文章 leeyc »

$.ajaxSettings.async = false;

多次呼叫API 會全部依順序跑完

$.ajaxSettings.async = true;
js 複製到剪貼簿
<button id="copy_c" style="float:right;margin-right:10px;">複製到剪貼簿</button>&nbsp;

        $('body').off('click', '#copy_c');
        $('body').on('click', '#copy_c', function () {
            //var outputElement = document.getElementById('output_id');
            copyTextFromElement('output_id');
        });

    //If you want to copyText from Element
    function copyTextFromElement(elementID) {
        let element = document.getElementById(elementID); //select the element
        let elementText = element.textContent; //get the text content from the element
        copyText(elementText); //use the copyText function below
    }

    //If you only want to put some Text in the Clipboard just use this function
    // and pass the string to copied as the argument.
    function copyText(text) {
        var dummy = document.createElement('textarea');
        document.body.appendChild(dummy);
        //console.log(text);
        dummy.value = text;
        dummy.select();
        document.execCommand('copy');
        document.body.removeChild(dummy);
    }
回覆文章