<span id="biao1" class="c3 ins">${loginSession}</span>
<input type="button" value="复制" id="copyBut" class="l30 w100 f12 cur cf bg-red bnone tc ibk ml25" />
实现点击复制span标签中的内容 js应该怎么写.使用了jquery框架!!
<script> function selectText(x) { if (document.selection) { var range = document.body.createTextRange();//ie range.moveToElementText(x); range.select(); } else if (window.getSelection) { var selection = window.getSelection(); var range = document.createRange(); selection.removeAllRanges(); range.selectNodeContents(x); selection.addRange(range); } //参考:http://blog.csdn.net/boyit0/article/details/41082941 } function cp(x) { selectText(x); document.execCommand("copy"); } </script> <span id="biao1" class="c3 ins">${loginSession}</span> <input type="button" value="复制" id="copyBut" onclick="cp(document.getElementById('biao1'));" class="l30 w100 f12 cur cf bg-red bnone tc ibk ml25" />
多谢!