zoukankan      html  css  js  c++  java
  • javascript: what can javascript do?

    1、Javascript can change html content

    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>What Can JavaScript Do?</h2>
    
    <p id="demo">JavaScript can change HTML content.</p>
    
    <button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button>
    
    </body>
    </html>

    2、Javascript can change html attributes

    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>What Can JavaScript Do?</h2>
    
    <p>JavaScript can change HTML attribute values.</p>
    
    <p>In this case JavaScript changes the value of the src (source) attribute of an image.</p>
    
    <button onclick="document.getElementById('myImage').src='pic_bulbon.gif'">Turn on the light</button>
    
    <img id="myImage" src="pic_bulboff.gif" style="100px">
    
    <button onclick="document.getElementById('myImage').src='pic_bulboff.gif'">Turn off the light</button>
    
    </body>
    </html>

    3、Javascript can change CSS style

    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>What Can JavaScript Do?</h2>
    
    <p id="demo">JavaScript can change the style of an HTML element.</p>
    
    <button type="button" onclick="document.getElementById('demo').style.fontSize='35px'">Click Me change Size!</button>
    
    
    <button type="button" onclick="document.getElementById('demo').style.backgroundColor='yellow'">Click Me change color!</button>
    
    </body>
    </html> 

    4、Javascript can change hide show html

    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>What Can JavaScript Do?</h2>
    
    <p>JavaScript can show hidden HTML elements.</p>
    
    <p id="demo" style="display:none">Hello JavaScript!</p>
    <p id="demo1" style="display:block">Hello JavaScript 001!</p>
    
    <button type="button" onclick="document.getElementById('demo').style.display='block'">Click Me to show!</button>
    
    
    <button type="button" onclick="document.getElementById('demo1').style.display='none'">Click Me to hide!</button>
    
    </body>
    </html> 
  • 相关阅读:
    LeetCode 35 搜索插入位置
    LeetCode 69 x 的平方根
    LeetCode 61 旋转链表
    LeetCode 876 链表的中间结点
    LeetCode 142 环形链表 II
    LeetCode 206 反转链表
    LeetCode 237 删除链表中的节点
    LeetCode 83 删除排序链表中的重复元素
    元素的隐藏与显示与判断 js jquery aspx.cs
    判断对象是否为空 js与Jquery区别
  • 原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/10609211.html
Copyright © 2011-2022 走看看