相同输入 id 的两个 onblur [英] Two onblur for same input id
本文介绍了相同输入 id 的两个 onblur的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的日常.我需要同时执行两个 onblur 功能.当有单个 onblur 时,下面的代码工作得很好.我如何修改我的代码以实现这两个功能.
Below is my routine. i need to do two onblur function at a mean time. below code works exact when there is single onblur. how can i modify my code to achieve both functionality.
HTML 编码:
<input type="text" name="frmEmail" id="frmEmail" class="textbox" value="Email Address" onfocus="if(this.value =='Email Address'){this.value=''}" onblur="if(this.value==''){this.value='Email Address'}" />
Javascript 编码:
Javascript coding:
function checkEmpty()
{
count=0;
if(document.getElementById('frmEmail').value=="Email Address") {
document.getElementById('frmEmail').style.backgroundColor = '#f6a9ae';
count++;
} else {
document.getElementById('frmEmail').style.backgroundColor = '';
}
if(count!=0) {
return false;
} else {
return true;
}
}
推荐答案
创建一个调用子例程的父"函数.
Create a 'parent' function that calls subroutines.
function myparent(){
dothis();
dothat();
}
更好的解决方案是为事件创建一个监听器,而不是内嵌一个处理程序,比如
A better solution is to create a listener to the event, instead of sticking a handler inline, such as
jQuery 方法:
<input id="myel">
$(function(){
$("#myel").blur(function() {
dothis();
dothat();
});
});
或者,非 jQuery 需要的纯 JS 方法:
Or, the non-jQuery required way with pure JS:
<input id="myel">
var myel = document.getElementById("myel");
myel.onblur = function() {
dothis();
dothat();
}
这篇关于相同输入 id 的两个 onblur的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文