我知道这是基本的,但我完全无法将"this"作为参数传递给JavaScript函数.我试着麻木了......
<!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>Untitled Document</title>
<script language="javascript" type="text/javascript">
function ko(control.id){
alert(control);
}
</script>
<body>
<div id"lala">
<a id="la" href="javascript:ko(this)" >Votes & Concerns</a>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
警报告诉我"未定义!"
ori*_*ori 12
<a id="la" href="#" onclick="ko(this); return false;" >Votes & Concerns</a>
Run Code Online (Sandbox Code Playgroud)
不要从"href"值执行此操作,请从实际事件处理程序属性执行此操作:
<a id='la' href='#' onclick='ko(event, this)'>
Run Code Online (Sandbox Code Playgroud)
传入,event以便您可以阻止<a>浏览器对点击的默认解释.
function ko(event, element) {
if ('preventDefault' in event) event.preventDefault();
event.returnValue = false; // for IE
// here "element" will refer to the clicked-on element ...
}
Run Code Online (Sandbox Code Playgroud)