

【JavaScript】html相关
source link: https://www.guofei.site/2019/08/25/javascript_html.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【JavaScript】html相关
2019年08月25日Author: Guofei
文章归类: 语言,文章编号: 17003
版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2019/08/25/javascript_html.html
JavaScript 代码嵌入html
3种方法:
- head中引用
- head中填入js
- body中填入js
<html>
<head>
<script src="test.js"></script> <!--引用js代码-->
<script>
<!--填入js代码-->
</script>
</head>
<body>
<script>
<!--填入js代码-->
</script>
</body>
</html>
demo
简洁版
<p id="demo"></p>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
复杂版
<!DOCTYPE html>
<html>
<head>
<script>
// 这一段代码可以放到head/引用/body中,都可以调用
function myFunction() {
document.getElementById("demo").innerHTML = "段落被更改。";
}
</script>
</head>
<body>
<h1>一张网页</h1>
<p id="demo">一个段落</p>
<button type="button" onclick="myFunction()">试一试</button>
</body>
</html>
几种显示方式
- 使用 window.alert() 写入警告框
- 使用 document.write() 写入 HTML 输出(就是整个页面变了)
- 使用 innerHTML 写入 HTML 元素
- 使用 console.log() 写入浏览器控制台
html事件
onchange
HTML 元素已被改变onclick
用户点击了 HTML 元素onmouseover
用户把鼠标移动到 HTML 元素上onmouseout
用户把鼠标移开 HTML 元素onkeydown
用户按下键盘按键onload
浏览器已经完成页面加载
File
其实一知半解
<input type="file" id="file" accept="image/*">
window.onload=function(){
let ofile=document.getElementById("file");
file.onchange = function () {
console.log(this.files[0]);
}
}
您的支持将鼓励我继续创作!
Recommend
-
23
Historia El desarrollo de la web va muy rápido. Todavía recuerdo los momentos en que empecé a usar jQuery, Prototype, script.aculo.us, Zepto y muchos más. Hoy en día, aunque nuestra aplicación se alimenta de herram...
-
393
Multiple Modals on One Page Using HTML, CSS, and JavaScript 09/07/2020: Consider whether this is something you really want to do. Opening multiple modals on one page isn’t great for a...
-
14
HTML to PDF JavaScript – Easily Convert Web Pages to PDFHey guys, today I have HTML to PDF JavaScript Tutorial for you all. Sometimes we need to give our users an option to download documents. You may need this featu...
-
11
解耦你的html,css和javascript 译 ...
-
10
POC : Implementing HTML 5 Video Element using JavaScript and Flash Tuesday, May 27, 2008 Since the first leg of the European on AIR Tour wrapped up, I have had some time to take som...
-
5
Video : Leveraging HTML / JavaScript in Apollo Wednesday, November 1, 2006 I have posted a video recording on the Leveraging HTML and JavaScript in A...
-
9
Removing HTML Element children with JavaScript Tuesday, January 24, 2006 Just a quick fyi, but if you are doing work in JavaScript and need to dynamically remove all of the childNodes from a DOM element, make sure to do...
-
13
解析 Html 自动生成目录 TOC 的相关代码function create_content_TOC(dom, config, target) { let hList = dom.find('h1,h2,h3,h4,h5,h6'); console.log(hList); target.html(''); if (!hList[0]) { target.html('')...
-
4
HTML概念和相关标签指南 原创 共饮一杯无 2022-06-23 09:25:17...
-
9
关于 html dom table 的相关操作本文摘自 勾三股四 更早时期的 不老歌 博客。[HTML DOM Table].cells[] [HTML DOM Table].rows[]
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK