javascript入门(一)

时间:2014-04-27 21:18:00   收藏:0   阅读:340

mamicode.com,码迷高手就可以直接跳过了,刚开始学习javascript,从零开始, 记录一点一滴,不断提高。菜鸟的不断成长。

下面就写上几个简单的JS  入门代码吧。高手就不要BS了mamicode.com,码迷

<!DOCTYPE html>
<html>

	<body>
		<script>
		function changeImage(){
			element=document.getElementById("myimage")
			if(element.src.match("bulbon")){
				element.src="i/eg_bulboff.gif";
			}else{
				element.src="i/eg_bulbon.gif";
			}
		}
		</script>
		
		<img id="myimage" onclick="changeImage()" src="i/eg_bulboff.gif" />
		
	</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>Jscript例子1</h1>
	<p id="demo">
	hello world.welcome to here.
	</p>
<script type="text/javascript">
		function myf(){
		x=document.getElementById("demo");
		x.innerHTML="你好,PPKER。欢迎来到JS";
		}
</script>
	<input type="button" onclick="myf()" value="点击">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>改变样式</h1>
	<p id="demo">
	德玛上单,不给就送啊!
	</p>
	<script type="text/javascript">
		function myf(){
			x=document.getElementById("demo");
			x.style.color="red";
		}
	</script>
	<input type="button" onclick="myf()" value="点击">
</body>
</html>
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /></head>
<body>
<input id="demo" type="text">
<script type="text/javascript">
function myf()
{
var x=document.getElementById("demo").value;
if(x==""||isNaN(x))
	{
	alert("姐,请输入数字");
	}else{
		alert("OK");
	}
}
</script>

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

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function  myf(){
		document.getElementById("demo").innerHTML="~~~上MISS了,嘿嘿嘿";
	}
</script>
</head>
<body>
	<p id="demo">努克萨斯</p>
	<button type="button" onclick="myf()">点击</button>
</body>
</html>
mamicode.com,码迷高手就不要BS了,都是从菜鸟开始的。别总是在想如何学好,坚持下去吧。无他,唯孰而已。





评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!