ling811的专栏

随心所动,自由翱翔

js的一些基础
js的编程用法:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<script>
document.write("<h1>这个是write,写入</h1>");
document.write('<p>这是内容</p>');
</script>
<br />
························································································
<button type="button" onclick="alert('JavaScript 能够对事件作出反应。(alert事件)')">猛戳</button>
<br />························································································
<br />
<script>
function myFunction(){
    x=document.getElementById("demo");
    x.innerHTML="被改变的内容和样式"
    x.style.color="#ff0000";
}
</script>
<p id="demo">JavaScript:改变 HTML 内容</p>
<button type="button" onclick="myFunction()">猛戳这里</button>
<br />
························································································<br />
<p>javascript改变图像</p>
<script>
    function changeImage(){
        element = document.getElementById("myimage")
        if(element.src.match("bulbon")){
            element.src="./eg_bulboff.gif";    
        }else{
            element.src="./eg_bulbon.gif"
        }    
    }
</script>
<img src="./eg_bulboff.gif" id="myimage" onclick="changeImage()"  />
<br />
·······································································
<br />
<script>
    function mytext(){
        var x=document.getElementById("text-demo").value;
        if(x==""||isNaN(x)){
            alert("您输入的不是数字");
        }
    }
</script>
<input type="text" id="text-demo" />
<button type="button" onclick="mytext()">点击</button>
<br />···························································<br />
<button type="button" onclick="myvar()">点击</button>
<p id="demo1"></p>
<script>
    function myvar(){
        var carname = "定义变量";
        document.getElementById("demo1").innerHTML=carname;
    }
</script>
</body>
</html>


相对应的效果图:


阅读更多
版权声明:原创文章,请标明出处~~~ https://blog.csdn.net/ling811/article/details/17162637
文章标签: js 基础 用法
想对作者说点什么? 我来说一句

C#实现的基本算法

zgqtxwd zgqtxwd

2008-04-24 08:42:00

阅读数:212

Eclipse基础设置

2017年09月04日 10KB 下载

没有更多推荐了,返回首页

不良信息举报

js的一些基础

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭