NO.1 你好,世界!
摘要
- 我们可以使用
<script>
标记将JavaScript代码添加到页面。 - 将
type
和language
属性不是必需的。 - 可以插入外部文件中的脚本
<script src="path/to/script.js"></script>
。
任务
我们现在实现一个小例子那就是在页面上和打印台上都显示hello-world
参考答案
JavaScript
<div>
<h1 id:"title">
....
</h1>
</div>
<script>
var a = document.getElementById('title');//获取元素
a.innerText = 'hello-world';
var b = document.getElementById('title');
console.log(b)//hello-world
</script>
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
jquery
$('#title').text('hello-word');
1