首页javascriptanchorJavascript Element - 如何向锚点元素添加单击事件处理程序...

Javascript Element - 如何向锚点元素添加单击事件处理程序...

我们想知道如何向锚点元素添加单击事件处理程序。...

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
var catagor;
function foo(){
    catagor = 'worldru';
    document.getElementById('printableArea').innerHTML = "<a href='javascript:void(0);' onClick='changePage(\"" + catagor + "\")'> CLICK HERE</a>";
}
function changePage(url){
    console.log('Parameter passed: ' + url);
}

</script>
</head>
<body>
<body onload="foo()">
  <div id="printableArea"></div>
</body>
</body>
</html>