补充一下:例如:
在 HTML中
<input type="button" value="提交" id="ss" onclick="show()"/><script>
function show(){
if(1=1){
return false;
}else{
return true;
}
}
</script>
假设,已知id="ss" 但不知道onclick事件的函数名为“show()”能否获取onclick事件的返回值是什么?
在 HTML中
<input type="button" value="提交" id="ss" onclick="show()"/><script>
function show(){
if(1=1){
return false;
}else{
return true;
}
}
</script>
假设,已知id="ss" 但不知道onclick事件的函数名为“show()”能否获取onclick事件的返回值是什么?
一种 直接onclick='' 另一种$('ss').click
不知道函数名 也是可以触发事件函数的。如:var box=document.getElementById('box');
function foo(){ alert(''); return 'click';}
box.onclick=foo;var str=box.onclick();//自动触发事件函数 并将返回值赋给变量str
alert(str);ps:具体如何触发 也要看如何绑定以及绑定的什么事件。
var elem = document.getElementById("ss");
elem.onclick();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script><script type="text/javascript" > function show(){
if(1==1){
return 1;
}else{
return 2;
}
}
function load(){
var fun=document.getElementById("fix").onclick;
alert(fun.call());
}
</script></head>
<body onload="load()">
<input id="fix" type="button" value="fff" onclick="return show()"/></body>
</html> 你的onclick 要有返回值。