<tr>
    <td>URL(服务器地址)</td>
    <td class="apiUrl"><span id="apiUrl">{$mp.url}</span><span class="tip1 rha-bt-a"></span></td>
    <td><a href="javascript:;" rel="external nofollow"  onclick="BtnClick('apiUrl','.tip1')" class="rha-bt-a">复制</a></td></tr>

js代码

<script type="text/javascript">    function copyText(text) {        var textarea = document.createElement("textarea");        var currentFocus = document.activeElement;        document.body.appendChild(textarea);
        textarea.value = text;
        textarea.focus();        if (textarea.setSelectionRange)
            textarea.setSelectionRange(0, textarea.value.length);        else
            textarea.select();        try {            var flag = document.execCommand("copy");
        } catch (eo) {            var flag = false;
        }        document.body.removeChild(textarea);
        currentFocus.focus();        return flag;
    }    function BtnClick(name,tip) {        var a = document.getElementById(name).innerHTML;        var flag = copyText(a);//这个必须在DOM对象的事件线程中执行
        var textlog = flag ? "复制成功!" : "复制失败!";        //展示后2秒消失
        $(tip).fadeIn();
        $(tip).insertAfter($(tip)).html(textlog).fadeOut(2000);
    };</script>