有关input标签做了一些总结

1、返回历史上一页

onclick="window.history.go(-1)"

2、重置按钮

onclick="javascript:window.history.back();"

3、输入框字数限制

<input type="text" id="name" maxlength="20" placeholder="最大长度为20"/>
$(document).ready(function(){
     $("input#name").keyup(function(){
	 if ($("input#name").val().length >= 20){
	    parent.$.messager.alert("温馨提示","最多输入20个字符!","info");
	 } 
     });
});

说一下其中的几个属性:

maxlength:输入字段的最大长度;

placeholder:描述输入字段预期值的提示信息;

readonly:只读不可修改,设置了该属性的表单会被提交;

disabled:不可修改,设置了该属性的表单不会被提交。

4、只能输入正整数

onkeyup="value=value.replace(/[^\d]/,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/,''))"

5、点击输入框变色

id属性为:name
#name:HOVER{border:1px solid red;}

猜你喜欢

转载自blog.csdn.net/weixin_40106067/article/details/82011318
今日推荐