向 button 元素分配 onclick 事件:
<!doctype html> <html> <body> <p>点击按钮就可以执行 <em>displaydate()</em>函数。</p> <button onclick = "displaydate()">点击点击点击</button> <script> function displaydate() { document.getelementbyid("demo").innerhtml = date(); } </script> <p id = "demo">会展示日期</p> </body> </html>
2.
<!doctype html> <html> <body onload = "checkcookies()"> <script> function checkcookies() { try { if (navigator.cookieenabled == true) { alert("已启用 cookie") } else { alert("未启用 cookie") } } catch (err) { alert('asdf') } } </script> <p>提示框会告诉你,浏览器是否已启用 cookie。</p> </body> </html>
3.
<!doctype html> <html> <head> <script> function myf() { var x = document.getelementbyid("fname"); x.value = x.value.touppercase(); } </script> </head> <body> 请输入应为字符:<input type = "text" id = "fname" onchange = "myf()"> <p>当您离开输入字段时,会触发将输入文本转换为大写的函数。</p> </body> </html>
如对本文有疑问, 点击进行留言回复!!
vue源码实战render.js与$nextTick的异步调用
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
网友评论