js复制文本框内容到剪切板实现换行

JavaScript014

js复制文本框内容到剪切板实现换行,第1张

<script type="text/javascript">

function copyUrl2()

{

var Url2=document.getElementById("biao1").innerText

var oInput = document.createElement('input')

oInput.value = Url2

document.body.appendChild(oInput)

oInput.select()// 选择对象

document.execCommand("Copy")// 执行浏览器复制命令

oInput.className = 'oInput'

oInput.style.display='none'

alert('复制成功')

}

</script>

<div cols="20" id="biao1">12345678</div>

<input type="button" onClick="copyUrl2()" value="点击复制代码" />

用document.write方法将文本输出到网页。

\n是JS换行符的转义符,BR标签是HTML的换行标签。

你用document.write方法将文本输出到网页,要在网页里产生换行效果,要用BR标签,因为浏览器会忽略换行符。

'asd'+'

'+'dsf' == 'asd

dsf'

<BR>是HTML4及以下版本的换行标签, <br />是XHTML1.0及以后版本的换行标签. 其实产生的效果是完全一致的, 只不过遵循的标准不同, 语法上有些差异。