日期:2014-05-16  浏览次数:20286 次

[急]手动触发事件如何获取执行的返回值?
<html>
<head>
<script>
function test1(a)
{
  document.getElementById("ipt").fireEvent("onblur");  
  //这里怎么获取test2执行后的返回值?触发事件不一定要用fireEvent,其他方法能获取到相似效果也可以。
}

function test2(obj)
{
  if (obj.value == 'test')
  {
  return false;  
  }
  return true;  
}
</script>
</head>
<body>
<input id="ipt" type="text" name="ipt" onblur="return test2(this)" />
<button onclick="test1()">test</button>

</body>
</html>

------解决方案--------------------
HTML code
<html>
<head>
<script>
function test1(a) {
    alert(document.getElementById("ipt").onblur()); 
}

function test2(obj) {
    return obj.value != 'test';
}
</script>
</head>
<body>
<input id="ipt" type="text" name="ipt" onblur="return test2(this)" />
<button onclick="test1()">test </button>
</body>
</html>

------解决方案--------------------
this?
HTML code

<html> 
<head> 
<script> 
function test1(a) 
{ 
    document.getElementById("ipt").fireEvent("onblur");  
    //这里怎么获取test2执行后的返回值?触发事件不一定要用fireEvent,其他方法能获取到相似效果也可以。 
    var e=document.getElementById("ipt").onblur();
    alert(e)
} 

function test2(obj) 
{ 
    if (obj.value == 'test') 
    { 
        return false;  
    } 
    return true;    
} 
</script> 
</head> 
<body> 
<input id="ipt" type="text" name="ipt" onblur="return test2(this)" /> 
<button onclick="test1()">test </button> 

</body> 
</html>