js基础

     前端js看着总是那么简单,自己写起来确实那么的难,这里主要是给自己做些记录

使用该标签可以直接在html页面输出文字

   

<script>
document.write("<h1>洪建雄</h1>");
document.write("<p>这是一个段落。</p>");
document.write("<h1>测试文件</h1>")
</script>


   点击触发函数

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>基础练习</title> 
</head>
<body>
<p>
JavaScript 能够对事件作出反应。比如对按钮的点击:
</p>
<button type="button" οnclick="alert('欢迎!')">点我!</button>
</body>
</html>

          通过javascript改变HTML里面的内容,代码如下:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
</head>
<body>
	
<h1>点击触发函数</h1>
<p id="demo">
 通过js改变内容
</p>
<script>
function myFunction()
{
	x=document.getElementById("demo");  // 找到元素
	x.innerHTML="擦鸟飞翔天!";    // 改变内容
}
</script>
<button type="button" οnclick="myFunction()">点击</button>
	
</body>
</html>

                    通过javascript改变HTML里面的内容样式,代码如下:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>改变内容样式</title> 
</head>
<body>
	
<h1>JavaScript</h1>

<script>
function myFunction()
{
	doc=document.getElementById("demo") // 找到元素
	doc.style.color="#ff0000";          // 改变样式
}
</script>
<button type="button" οnclick="myFunction()">点击这里</button>
	
</body>
</html>




  

  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值