html文本框不可编辑,禁止用户修改的几种方法是什么?

html文本框不可编辑,禁止用户修改的几种方法是什么?,第1张

具体步骤: \x0d\x0a方法一:设置readonly属性为true。\x0d\x0a\x0d\x0aHtml代码\x0d\x0a1. \x0d\x0a\x0d\x0a\x0d\x0a方法二:设置disabled属性为true。\x0d\x0a\x0d\x0aHtml代码\x0d\x0a1. \x0d\x0a\x0d\x0a\x0d\x0a方法三:在对象focus时立刻让它blur,使它无法获得焦点。\x0d\x0a\x0d\x0aHtml代码\x0d\x0a1. \x0d\x0a\x0d\x0a\x0d\x0a提示:readonly和disabled的区别在于后者完全禁止与设置该属性的对象交互(表现为不可改写、不可提交等)。

我给你做了段代码,注意,你那个复选框的id得跟下面的对应,这里我就用<input type="checkbox" name="aaa" id="aaa" />代替吧

=================================================================

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>无标题文档</title>

<script>

function check(){

if(!document.getElementById("aaa").checked){alert("你必须同意协议")return false}

return true

}

</script>

</head>

<body>

<form id="form1" name="form1" method="post" action="">

<div style="border:1px solid #acewidth:800pxheight:400pxmargin:5px autopadding:5px">用户协议</div>

<div style="width:800pxmargin:5px autotext-align:right">

<p>

<label>

<input type="checkbox" name="aaa" id="aaa" />

我同意</label>

</p>

<p>

<input type="submit" name="button" id="button" value="注册" onclick="return check()" />

</p>

</div>

</form>

</body>

</html>

js禁止文本框输入用'disabled'限制。

//HTML代码

<input type="text" id="text001" value="123"/>

//jQuery代码

$(function(){

$('#text001').attr('disabled',true)

})

要禁止输入其实可以不用js都可以做到

input有个属性readonly是用来设置文本框为只读的

只需要添加readonly='readonly'

就可以不让文本框输入文字了

例如<input type='text' readonly='readonly'/>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6103283.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-14
下一篇 2023-03-14

发表评论

登录后才能评论

评论列表(0条)

保存