html小代码

 

播放音乐和视频

<!DOCTYPE HTML> 

<html> 

<body> 

   <audio controls="controls">

<source src="1122qww.ogg" type="audio/ogg">

<source src="1122qqww.mp3" type="audio/mpeg">

</audio>

<video width="720" height="610" controls="controls">

<source src="Unix.ogg" type="video/ogg">

<source src="Unix.mp4" type="video/mp4">

</video>

</body> 

</html>

 

 

链接

<!DOCTYPE HTML> 

<html> 

<body> 

   <a href="mailto:us@example.org">

Email us

</a> <br />

<a href=" http://www.sina.com.cn ">

Visit sina.com.cn!

</a>  <br />

<a href=" http://www.baidu.com ">

Visit baidu!

</a> <br /> 

</body> 

</html>

 

 

 

创建button

<script language=JavaScriptd>

function judge() {

var score = prompt("are you fenshu?");

}

</script>

 

<form>

<input type="button" value="click it" onclick ="judge()">

</form>

 

<button onmouseover="judge()">show12</button>  

<!—onmouseover/ onmouseout/onclick—>

 

 

通过 JSON 字符串来创建js对象

<html>

<body>

<h4>通过 JSON 字符串来创建对象</h4>

<p>

First Name: <span id="fname"></span><br /> 

Last Name: <span id="lname"></span><br /> 

</p> 

<script type="text/javascript">

var txt = '{"employees":[' +

'{"firstName":"Bill","lastName":"Gates" },' +

'{"firstName":"George","lastName":"Bush" },' +

'{"firstName":"Thomas","lastName":"Carter" }]}';

 

var obj = eval ("(" + txt + ")");   <!—等效于   obj = JSON.parse(txt);—>

 

document.getElementById("fname").innerHTML=obj.employees[1].firstName 

document.getElementById("lname").innerHTML=obj.employees[1].lastName 

</script>

</body>

</html>

 

 JavaScript 中创建 JSON 对象

<html>

<body>

<h2>在 JavaScript 中创建 JSON 对象</h2>

 

<p>

Name: <span id="jname"></span><br />

Age: <span id="jage"></span><br />

Address: <span id="jstreet"></span><br />

Phone: <span id="jphone"></span><br />

</p>

 

<script type="text/javascript">

var JSONObject= {

"name":"Bill Gates",

"street":"Fifth Avenue New York 666",

"age":56,

"phone":"555 1234567"};

document.getElementById("jname").innerHTML=JSONObject.name

document.getElementById("jage").innerHTML=JSONObject.age

document.getElementById("jstreet").innerHTML=JSONObject.street

document.getElementById("jphone").innerHTML=JSONObject.phone

</script>

 

</body>

</html>

posted @ 2015-03-12 17:17  李xu  Views(231)  Comments(0Edit  收藏  举报