我想更改onclick的值,我尝试过,但没有成功。有什么帮助吗?
<a href='#' id='social' onClick="">click</a>
document.getElementById("social").onclick = "open_new_window('https://twitter.com/share?url=https%3A%2F%2F"+url+"&via=iguestblogger&text="+title+"');";
注:url
、title
和open_new_window()
已定义,工作正常。
不更改onclick
属性的值,只需绑定事件即可。
document.getElementById("social").onclick = function() {
open_new_window('https://twitter.com/share?url=https%3A%2F%2F'+url+'&via=iguestblogger&text='+title);
};
document.getElementById("social").onclick = function(){open_new_window('https://twitter.com/share?url=https%3A%2F%2F"+url+"&via=iguestblogger&text="+title+"');};
假设url和title以及函数open_new_window已经在前面定义过了,也要注意你的报价
<a href='#' id='social' >click</a>
<script>
document.getElementById("social").onclick = function()
open_new_window("https://twitter.com/share?url=https%3A%2F%2F"+url+"&via=iguestblogger&text="+encodeURI(title));
return false;
}
</script>
document.getElementById("social").onclick = open_new_window('https://twitter.com/share?url=https%3A%2F%2F"+url+"&via=iguestblogger&text="+title+"');