代码如下:首先,创建一个属性节点var attri=document.createAttribute("size")创建一个size属性节点
然后就可以对该size属性赋具体长度值了 attri.value="10"(假如要设置text文本框长度为10)
然后利用inputTxta对象将该属性节点添加到input标记中 inputTxta.setAttribute(attri)
搞定,呵呵,希望对你有所帮助!
this.areaDom=document.createElement("textarea")
this.areaDom.id="selectedUser"
this.areaDom.style.width = "12px"
this.areaDom.style["height"] = "auto"
<script>var p = /^[\d]{11}$/ // 正则 表示 开头为数字 要11位 结尾
function chk(n) { // 检测函数
if(!p.test(n.value)) { // 检测值input的值是否由数字组合并要11位 如果不是则提示
alert('只允许数字并要11位')
n.select() // 选中输入框内容
}
}
</script>
<body>
<input type="text" name="name" onblur="chk(this)"/><!-- 失去焦点时开始检测 调用chk函数 -->
</body>