设置文本框不允许有焦点:
<input type="text" disabled="disabled">
设置confirm()中的文本内容:
confirm("您本次购买的商品信息如下:\n商品名称:跑跑游戏道具;\n商品数量:5件;\n商品单价:12.5");
\n即代表换行
设置全屏漂浮广告:
<script language="javascript">
var x = 50,y = 60; //浮动广告初始位置
var xin = true, yin = true; //xin为真,则向右运动,否则向左运动;
//yin为真,则向下运动,否则向上运动
var step = 1; //移动的距离
var delay = 10; //移动的事件间隔
function floatAD(){
var L=T=0; //L左边界,T上边界
var R =
document.body.offsetHeight-document.getElementByIdx_x_x("fly").offsetWidth;
//层移动的右边界
var B =
document.body.offsetHeight-document.getElementByIdx_x_x("fly").offsetHeight;
//层移动的下边界
document.getElementByIdx_x_x("fly").style.left = x ; //层移动后的左边界
document.getElementByIdx_x_x("fly").style.top = y ;
//层移动后的上边界
x = x + step * (xin ? 1 :
-1); //判断水平方向
if(x < L){xin = true; x =
L;} //到达边界后的处理
if(x > R){xin = false; x = R;}
y = y + step * (yin ? 1 : -1);
if(y < T){yin = true; y =
T;}
if(y > B){yin = false; y = B;}
setTimeout("floatAD()",delay) //隔多久调用一次
}
</script>
如何利用JS:
oncontextmenu="window.event.returnValue=false"
将彻底屏蔽鼠标右键
<body onselectstart="return
false">
取消选取、防止复制
onpaste="return
false"
不准粘贴
oncopy="return false;" oncut="return
false;"
防止复制
-----------------------------------
1.右键无效
view plaincopy to
clipboardprint
<script>
document.oncontextmenu=new
Function("event.returnValue=false;");
</script>
<body>
右键无效
</body>
2.禁止网页复制
view plaincopy to clipboardprint?
<body>
<script
type="text/javascript">
document.body.oncopy=nocopy;
function
nocopy(){
clipboarData.setData("text","");
setTimeout(nocopydelay,100);
}
function
nocopydelay(){
alert("不能复制");
clipboarData.setData("text","哈哈"+"\r\n文章来自:sxzlc详细参考:"+location.href);
}
</script>
无法复制,但是internet选项安全脚本活动脚本禁用后就可以复制了。<br>
需要使用一下延时。
script要在body内部,否则不好使。
强烈建议没有什么特殊要求别在自己的网页上这么弄。
</body>
3.禁止F5刷新
view plaincopy to
clipboardprint?
<script
type="text/javascript">
document.onkeydown=function()//禁止刷新
{
if(event.keyCode==116){
event.keyCode=0;
event.returnValue=false;
}
}
document.oncontextmenu=function(){
event.returnValue=false;
}
</script>
4.js中的alert的意外发现,以前不知道。
view plaincopy to clipboardprint?
<script
type="text/javascript">
function
sss()
{
alert(sss);
alert('sss');
}
</script>
<body
onload=sss();>
运行一下,非常有意思。
第一个,会把函数的内容显示出来,对话框的内容是:function
sss(){....}
第二个输出才是sss
</body>
5.屏蔽js错误
<script language="javascript">
<!--
function
killerrors() {
return true;
}
window.onerror =
killerrors;
//-->
</script>
<mec:script
language="javascript">
function
sss(){
alert(sss);
alert('sss');
alert(aaaaa);
}
</script>
<body
onload=sss();>
代码中注释去掉与否没有影响!
</body>
6.禁用backspace退格键
function
document.onkeydown(){
if(event.keyCode==8){
if(document.activeElement.type=="text"){
if(document.activeElement.readOnly==false)
return
true;
}
return false;
}
}