当我使用document.execCommand(“copy”)时,javascript换行符不适用

前端之家收集整理的这篇文章主要介绍了当我使用document.execCommand(“copy”)时,javascript换行符不适用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我正在使用下面的代码来构建一个字符串并复制它,但在输出时,当我粘贴它时,换行符不适用
function copyToClipboardShipto() {
        var $temp = $("<input>");

        $("body").append($temp);
        var str1 = "@(Model.firstName)"; var str2 = " "; var str3 = "@(Model.lastName)"; var str4 = "\n";
        var str5 = "@(Model.shiptoes[0].address.address1)";
        var str6 = ",";
        var str7 = "@(Model.shiptoes[0].address.address2)";
        var str8 = "\n";
        var str9 = "@(Model.shiptoes[0].address.city)"; var str10 = ","; var str11 = "@(Model.shiptoes[0].address.state)"; var str12 = "\n";
        var str13 = "@(Model.shiptoes[0].address.zip)";
        var str = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10 + str11 + str12 + str13;
        $temp.val(str).select();
        document.execCommand("copy");
        $temp.remove();
    }
}

名字lastname223 E JACKSON AVE,city,statezip
有任何帮助

解决方法

使用< textarea>而不是< input>,因为INPUT不支持多行字符串.
var $temp = $("<textarea>");
原文链接:https://www.f2er.com/js/156020.html

猜你在找的JavaScript相关文章