js 复制某一个div中的内容

仅支持IE, 不支持 FireFox

     function copyToClipboard() {
        try {
            var txt = document.getElementById("divLog").innerText;
            window.clipboardData.setData('text', txt);
            alert('Copy Done,use "Ctrl+V" to paste!');
        } catch (e) {
            alert('Your browser can not support clipboard, please copy the content by your self!');
        }
    }


mvc4, razor 中 .cshtml 部分前端代码:

    @if (Model != null)
    {
        <div style="width: 95%">
            <h4>
                Review Log</h4>
            <table style="border:0;width:100%">
                <tr>
                    <td align="right" width="5%">
                        <input type="button" value="Click to Copy" onclick="copyToClipboard();" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <div id="divLog" style="border: 1px solid gray; width: 100%; height: 200px; line-height: 200px;
                            overflow: auto; overflow-x: hidden;">
                            <table>
                                <tr>
                                    <td>
                                        @foreach (var item in Model.LstPkgRV_Log)
                                        {
                                            @Html.Raw(item.Log.ToString())
                                        }
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    }


没有更多推荐了,返回首页