var img = this.value;//获取的是一个临时地址c:\fakepath\图片名

if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(img)){

alert("选择的文件格式不对")

return false;

}

var f = this.file[0];

var src = window.URL.createObjectURL(f);

$(this).prev().attr("src",src);//当前JQ代理对象上面的DOM元素

})

2、判断复选框状态

这里有三种方法:

第一种(通过is方法判断):if($("input[type='checked']").is(":checked")){

被选中状态需要做什么

}

第二种(通过prop获取属性值方法):if($("input[type='checked']").prop("checked")){

被选中状态需要做什么

}

一般获取状态属性的值都选择用prop而不用attr

第三种:if($("input[type='checked']")).get(0).checked){

被选中状态需要做什么

}

同样可以判断状态,那也可以改变状态:

$("input[type='checked']").prop("checked","true");//选中

$("input[type='checked']").prop("checked","false");//不选中

同样selected也可以这样判断和修改

3、文本框不能编辑属性:readonly

<input type="text" redaonly />只读文本框,不能进行编辑

4、去除input文本框点击边框

input{outline:none;}

5.只能为中文

<input type="text" onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9" />

6.只能为数字

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

7.只能输入英文和数字

<input type="text" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />

Tags:

猜你喜欢

最近发表
标签列表