一、表单标签焦点
<input type="text" placeholder="请输入姓名">
<script>
window.onload = function (ev) {
var input = document.getElementsByTagName("input")[0];
input.onfocus = function (ev1) {
this.style.width = '600px';
this.style.height = '40px';
this.style.outline = 'none';
this.style.fontSize = '20px';
}
input.onblur = function (ev2) {
this.style.border = '10px solid red';
this.style.height = '40px';
}
}
</script>
不点击输入输入框时的默认样式 点击了输入框之后 再点击其他空白处的时候
二、对上传文件进行格式筛选
<label for="">上传图片:</label>
<input type="file" id="file"><!--file就是上传文件的按钮-->
<!--jpg png gif 格式的图片才能上传-->
<script>
window.onload = function (ev) {
var file = document.getElementById("file");
file.onchange = function (ev2) {
console.log("上传文件了");
var path = this.value;
var suffix = path.substr(path.lastIndexOf('.'));
console.log(suffix);
var lowerSuffix = suffix.toLowerCase();
if(lowerSuffix === ".jpg" || lowerSuffix === '.png' || lowerSuffix === '.gif'){
alert("上传成功");
}else{
alert("上传格式不正确,只能jpg\\png\\gif");
}
}
}
</script>
上传一个文件不是.jpg.png.gif后缀的 上传一张图片1.jpg
三、源码:
D36_1_CommonAffairOfInputLable.htmlD36_2_FormatVerificationOfUploadingImage.html地址:https://github.com/ruigege66/JavaScript/blob/master/D36_1_CommonAffairOfInputLable.htmlhttps://github.com/ruigege66/JavaScript/blob/master/D36_2_FormatVerificationOfUploadingImage.html博客园:https://www.cnblogs.com/ruigege0000/:https://blog.csdn.net/weixin_44630050?t=1欢迎关注微信公众号:傅里叶变换,个人账号,仅用于技术交流
转载请注明原文地址:https://blackberry.8miu.com/read-7483.html