javascript语言精萃

概述

  • 世界上最流行的脚本语言
  • 兼容性强
  • 为html增强交互
  • 语法简单
    javascript的实现
  • 必须置于之间
  • 中的js函数
  • 中的js函数
  • 外部js文件
    javascript的输出

  • js操作html元素(element)

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<p id="demo">My First Paragraph</p>

<script>
document.getElementById("demo").innerHTML="My First JavaScript";
</script>
</body>
</html>

写到文档输出
下面的例子直接把

元素写到 HTML 文档输出中:

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<script>
document.write("<p>My First JavaScript</p>");
</script>

</body>
</html>

警告
请使用 document.write() 仅仅向文档输出写内容。
如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖:

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<p>My First Paragraph.</p>

<button onclick="myFunction()">点击这里</button>

<script>
function myFunction()
{
document.write("糟糕!文档消失了。");
}
</script>

</body>
</html>

事件onmouseover and onmouseout

<!DOCTYPE html>
<html>
<body>
<div style="background-color:green;color:#fff;width:120px;
height:20px;padding:40px;margin:20px;box-shadow:10px 10px 10px #fff;" onmouseover="Onover(this)" onmouseout="Onout(this)">移动鼠标点击</div></br>

<div style="background-color:green;color="#fff";font-size:13px;padding:40px;width:120px;height:20px;"onmouedown="Ondown(this)";onmouseup="Onup(this)">移动鼠标</div>

<script>
function Onover(obj)
{
    obj.innerHTML="谢谢"
}
function Onout(obj)
{
    obj.innerHTML="把鼠标移走"
}
function Ondown(obj)
{
 obj.innerHTML="按住鼠标";
 obj.style.background-color="#1ec5e5"
 }
 function Onup(obj)
 {
     obj.innerHTML="松开鼠标";
     obj.style.background-color="green"
 }
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值