clipboard copy does not work in jquery ajax success method

后端 未结 6 1537
Happy的楠姐
Happy的楠姐 2021-01-14 03:38

I want to copy a card number into the clipboard so that I can paste it in Notepad. The code which I got from the internet works very well if tried in the developer toolbar o

6条回答
  •  清酒与你
    2021-01-14 04:11

    Well, what are you copying? document.execCommand("copy"); requires something to be selected(highlighted) in the first place.

    I think in your example, select follows .val(). But in order for this to work you need to be selecting an element, not it's value.

    $temp.val(data.CardNumber);
    $temp.select();
    
    copied = document.execCommand("copy");
    $temp.remove();
    
    if(copied){
        alert('copied successfully');
    }else{
        alert('something went wrong');
    }
    

提交回复
热议问题