Javascript Element - 如何向錨點(diǎn)元素添加單擊事件處理程序...
我們想知道如何向錨點(diǎn)元素添加單擊事件處理程序。...
<!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>
The code above is rendered as follows: