为什么我复制到剪贴板不起作用,请帮助我。
在我的代码中,我想复制邮件。这是由ajax加载数据的函数。
var listCopy = [];
listCopy = getSelectableList(_this);
var arr_post = {
relationshipId: listCopy,
};
uiCopy = '';
var data_end = $.ajax({
url: APP_BASE_URL + 'index.php/chat/getContentMessageCopy',
type: 'POST',
data: arr_post,
async: false,
beforeSend: function(argument) {
// that.attr('disabled', 'true');
},
success: function(data) {
var result = JSON.parse(data);
uiCopy = '<div class="copy_message">';
$.each(result, function( index, value ) {
uiCopy += '<div class="copy_message_content">' + value[0].CONTENT + '</div>';
});
uiCopy += '<div class="copy_message_auth">' + result[0][0].SENDER_NAME + '</div>';
uiCopy += '<div class="copy_message_time">' + result[0][0].SEND_DATE + '</div>';
uiCopy += '</div>';
uiCopy = '//copy:' + uiCopy;
return data;
}
}).responseText;
pushToClipboard(uiCopy);
function pushToClipboard(stringCopy) {
var stringBufferCopy = stringCopy;
var input = '<textarea id="temporary" style="position:absolute;opacity:0;"></textarea>';
clipboardBuffer = '<textarea id="txtInputBuffer" style="position:absolute;opacity:0;" class="answer-text-area" maxlength="3000" spellcheck="false" >' + stringBufferCopy + '</textarea>';
$("body").append(input);
$("body").append(clipboardBuffer);
$("#temporary").val($("#txtInputBuffer").text()).focus().select();
document.execCommand("copy");
$("#temporary").remove();
$("#txtInputBuffer").remove();
if (window.clipboardData) {
window.clipboardData.setData('Text', stringCopy);
}
}
正常,函数document.execCommand(&#34; copy&#34;)它正常工作,但是如果通过ajax加载数据不起作用。