JS检查当图片不存在时显示默认图片和键盘大小写键状态

时间:2020-12-04 20:13:53

当图片不存在时显示默认图片

 <script type="text/javascript">
var imgs = document.images;
for(var i = 0;i < imgs.length;i++){
imgs[i].onerror = function(){
this.src = "http://images2015.cnblogs.com/blog/66516/201511/66516-20151104233425055-1712623285.png";
}
}
</script>

或者:

 <img src="" border="0" onerror="this.src=' http://images2015.cnblogs.com/blog/66516/201511/66516-20151104233425055-1712623285.png'"/>

键盘大小写键状态

 <script type="text/javascript">
function detectCapsLock(event) {
var e = event || window.event;
var o = e.target || e.srcElement;
var oTip = o.nextSibling;
var keyCode = e.keyCode || e.which; // 按键的keyCode
var isShift = e.shiftKey || (keyCode == 16) || false; // shift键是否按住
if (
((keyCode >= 65 && keyCode <= 90) && !isShift) // Caps Lock 打开,且没有按住shift键
|| ((keyCode >= 97 && keyCode <= 122) && isShift)// Caps Lock 打开,且按住shift键
) {
oTip.style.display = '';
}
else {
oTip.style.display = 'none';
}
} window.onload = function () {
document.getElementById('<%= txtUserName.ClientID %>').focus();
document.getElementById('<%= txtPassword.ClientID %>').onkeypress = detectCapsLock;
};
</script>