javascript 限制輸入和粘貼(IE,firefox測試通過)

來源:互聯網
上載者:User

複製代碼 代碼如下:window["MzBrowser"] ={};
(function()
{
if(MzBrowser.platform) return;
var ua = window.navigator.userAgent;
MzBrowser.platform = window.navigator.platform;
MzBrowser.firefox = ua.indexOf("Firefox") > 0;
MzBrowser.opera = typeof(window.opera) == "object";
MzBrowser.ie = ! MzBrowser.opera && ua.indexOf("MSIE") > 0;
MzBrowser.mozilla = window.navigator.product == "Gecko";
MzBrowser.netscape = window.navigator.vendor == "Netscape";
MzBrowser.safari = ua.indexOf("Safari") > - 1;
if(MzBrowser.firefox) var re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.ie) var re = /MSIE( )(\d+(\.\d+)?)/;
else if(MzBrowser.opera) var re = /Opera(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.netscape) var re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.safari) var re = /Version(\/)(\d+(\.\d+)?)/;
else if(MzBrowser.mozilla) var re = /rv(\:)(\d+(\.\d+)?)/;
if("undefined" != typeof(re) && re.test(ua))
MzBrowser.version = parseFloat(RegExp.$2);
}
)();
function upLoadKey(e, object)
{
if((document.all) ? true : false)
{
window.event.keyCode == 9 ? (window.event.returnValue = true) : (window.event.returnValue = false);
}
else
{
if(object.value == "" && typeof e.which == "number")e.preventDefault();
if(object.value != "") object.blur();
}
}
function version(object)
{
if(MzBrowser.firefox && MzBrowser.version == 2)object.blur();
}
function clearValue(id)
{
var up = (typeof id == "string") ? document.getElementById(id) : id;
if (typeof up != "object") return null;
var tt = document.createElement("span");
tt.id = "__tt__";
up.parentNode.insertBefore(tt, up);
var tf = document.createElement("form");
tf.appendChild(up);
document.getElementsByTagName("body")[0].appendChild(tf);
tf.reset();
tt.parentNode.insertBefore(up, tt);
tt.parentNode.removeChild(tt);
tt = null;
tf.parentNode.removeChild(tf);
}

// 頁面代碼 複製代碼 代碼如下:<html>
<head>
<script language="javascript" src="upLoad.js"></script>
</head>
<body>
<input name="textfield3" type="file" class="input" id="textfield3" size="30" value="" ondrag="return false;" oncut="return false;" onkeydown="upLoadKey(event,this);" onpaste="return false;" onmousedown="document.oncontextmenu = function() { return false;}" onmouseout="document.oncontextmenu = function() { return true;};version(this);" tabIndex = -1/> <input type="button" id="clear" value="清 空" onclick="clearValue('textfield3');"/>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.