js 怎么清除粘贴过来的内容的样式

JavaScript015

js 怎么清除粘贴过来的内容的样式,第1张

1. 去掉字符串两端的空格

String.prototype.trim=function (){return this.replace(/(^/s*)|(/s*$)/g,'')}

2. 去掉字符串中所有的空格:

String.prototype.sTrim = function (){return this.replace(//s/g, '')}

或者:

var s = "asd ddd bbb sss"

var reg = //s/g

var ss = s.replace(reg, "")

alert(ss)

1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键,其实是禁止快捷菜单,因为不光右键可以弹出这个菜单,键盘上空格键右边的windows键也可以激活这个快捷菜单

<table border oncontextmenu=return(false)><td>no</table>可用于Table

2. <body onselectstart="return false">禁止选取、防止复制

3. onpaste="return false" 禁止粘贴

4. oncopy="return false" oncut="return false" 禁止复制和剪切

5. <input style="ime-mode:disabled">关闭输入法

<!-- 禁止选择文本: -->

<script type="text/javascript">

var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){

if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)

return false

}

function reEnable(){

return true

}

if (typeof document.onselectstart!="undefined")

document.onselectstart=new Function ("return false")

else{

document.onmousedown=disableselect

document.onmouseup=reEnable

}

</script>

<!-- 禁用右键: -->

<script>

function stop(){

return false

}

document.oncontextmenu=stop

</script>

功能:禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt

<script language="JavaScript">

<!--

function key(){

if(event.shiftKey){

window.close()}

//禁止Shift

if(event.altKey){

window.close()}

//禁止Alt

if(event.ctrlKey){

window.close()}

//禁止Ctrl

return false}

document.onkeydown=key

if (window.Event)

document.captureEvents(Event.MOUSEUP)

function nocontextmenu(){

event.cancelBubble = true

event.returnValue = false

return false}

function norightclick(e){

if (window.Event){

if (e.which == 2 || e.which == 3)

return false}

else

if (event.button == 2 || event.button == 3){

event.cancelBubble = true

event.returnValue = false

return false}

}

//禁右键

document.oncontextmenu = nocontextmenu // for IE5+

document.onmousedown = norightclick // for all others

//-->

</script>

<body onselectstart="return false"onpaste="return false">