触发 onclick
属性事件当单击元素上的鼠标按钮时。
没有。
<element onclick="script or Javascript function name">
所有HTML元素,EXCEPT:
<base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, <title>
onclick |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
console.log("clicked");
}
</script>
</body>
</html>
Click to view the demo
下面的代码显示了如何处理鼠标点击事件。
<html>
<head>
<script language="JavaScript">
function addunderline() {
head1.style.textDecoration = "underline"
}
function removeunderline() {
head1.style.textDecoration = "none"
}
function addoverline() {
head1.style.textDecoration = "overline"
}
function addlinethrough() {
head1.style.textDecoration = "line-through"
}
</script>
</head>
<body>
<h1 id="head1"
onMouseover="addunderline()"
onMouseout="removeunderline()"
onClick="addoverline()"
ondblclick="addlinethrough()">Welcome to this page!</h1>
<P>A lot of interesting text goes here!</p>
</body>
</html>
Click to view the demo
HTML5 onafterprint 事件属性 HTML 事件属性实例在页面设置打印及打印对话框出现后执行 JavaScript :body onafterprint="printms...
HTML 音频/视频 DOM mediaGroup 属性 HTML 音频/视频 DOM 参考手册实例为两段视频设置媒体组合:myVid1=document.getElementById...
HTML 参考手册- (HTML5 标准)功能排序New: HTML5 新标签标签描述基础!DOCTYPE定义文档类型。html定义一个 HTML 文档title为文档...