欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

html组件不可输入(只读)同时任何组件都有效_jquery

程序员文章站 2022-03-31 09:42:09
...
复制代码 代码如下:

/**
* 将页面设置为只读
*/
var setReadOnly = function()
{
var input = $("input");
input.each(function(i)
{
$(this).attr("onfocus", "this.blur();return false;");
$(this).wrap(function()
{
return '';
});
});
var select = $("select");
select.each(function(i)
{
$(this).attr("onfocus", "this.blur();return false;");
$(this).wrap(function()
{
return '';
});
});
var textarea = $("textarea");
textarea.each(function(i)
{
$(this).attr("onfocus", "this.blur();return false;");
$(this).wrap(function()
{
return '';
});
});
var img = $("img");
img.each(function(i)
{
$(this).attr("onfocus", "this.blur();return false;");
$(this).wrap(function()
{
return '';
});
});
}