我正在尝试在点击事件上调用setVideo()
函数。但是当它嵌入在html中时,由于括号而立即被执行。内联式是唯一的方法吗?
<script>
window.onload = rv_clicked;
function rv_clicked() {
var v_links = document.querySelectorAll("#recommendation img");
for (var i = 0; i < v_links.length; i++) {
// this gets executed right away:
v_links[i].onclick = setVideo(v_links[i].title);
}
}
</script>