我的JS函数大全
2005-06-03 15:34
405 查看
一、实现动态创建元素,并把元素内容复制到粘贴板上。
function CreateElementToCopyValue(val)
{
var tt = document.createElement("input");
tt.type = "text";
tt.value = val;
document.body.appendChild(tt);
tt.createTextRange().select();
document.selection.createRange().execCommand("Copy"); // Or "Paste"
}
二、复制指定控件上的内容到粘贴板上。
<input id="copytxt" type="text" value="" size="50"><input type="button" value="点击复制地址" onclick="copyit()">
<script>
document.getElementById('copytxt').value = document.URL;
function copyit()
{
var obj = document.getElementById('copytxt');
obj.select();
var js = obj.createTextRange();
js.execCommand("Copy");
alert("复制成功!");
}
</script>
三、获取键盘按键。
window.event.keyCode
四、禁止右键播放器 Realplay。
<body onload="initPlayer()">
<script language="javascript">
function initPlayer()
{
document.player.SetWantMouseEvents(true)
}
function noRB()
{
setTimeout("alert('右键禁止')",400)
}
</script>
<script language="vbscript">
sub player_OnRButtonDown(ByVal nFlags, ByVal nX, ByVal nY)
if player.getfullscreen() then
player.SetOriginalSize()
noRB()
else
msgbox("右键禁止")
end if
End Sub
</script>
五、按回车键直接代替Tab键
function document.onkeydown()
{
if(event.keyCode==13 && event.srcElement.type !="BUTTON" && event.srcElement.type!="SUBMIT")
event.keyCode=9;
}
//和按 Tab 键的效果一样
function CreateElementToCopyValue(val)
{
var tt = document.createElement("input");
tt.type = "text";
tt.value = val;
document.body.appendChild(tt);
tt.createTextRange().select();
document.selection.createRange().execCommand("Copy"); // Or "Paste"
}
二、复制指定控件上的内容到粘贴板上。
<input id="copytxt" type="text" value="" size="50"><input type="button" value="点击复制地址" onclick="copyit()">
<script>
document.getElementById('copytxt').value = document.URL;
function copyit()
{
var obj = document.getElementById('copytxt');
obj.select();
var js = obj.createTextRange();
js.execCommand("Copy");
alert("复制成功!");
}
</script>
三、获取键盘按键。
window.event.keyCode
四、禁止右键播放器 Realplay。
<body onload="initPlayer()">
<script language="javascript">
function initPlayer()
{
document.player.SetWantMouseEvents(true)
}
function noRB()
{
setTimeout("alert('右键禁止')",400)
}
</script>
<script language="vbscript">
sub player_OnRButtonDown(ByVal nFlags, ByVal nX, ByVal nY)
if player.getfullscreen() then
player.SetOriginalSize()
noRB()
else
msgbox("右键禁止")
end if
End Sub
</script>
五、按回车键直接代替Tab键
function document.onkeydown()
{
if(event.keyCode==13 && event.srcElement.type !="BUTTON" && event.srcElement.type!="SUBMIT")
event.keyCode=9;
}
//和按 Tab 键的效果一样