HTML学习三

今天主要学习的为JS和HTML标签的一起使用:

 

一、重定向:

<html>
	<head>
		<title>JavaScript1</title>
	</head>
	<script type="text/javascript" language="javascript">
	   function fun(value)
	   {
			window.location = value;
	   }
	</script>
	<body>
	    <select name="url" onchange="fun(this.value)">
		   <option value="">==select==</option>
		   <option value="http://www.baidu.com">baidu</option>
		   <option value="http://www.sohu.com">sohu</option>
		</select>
	</body>
</html>

  

 

二、全选

 

<html>
	<head>
		<title>JavaScript2</title>
		<script type="text/javascript" language="javascript">
			function funAll()
			{
				if(document.all("email").length == undefined )
				{
					document.all("email").checked = document.all("selectall").checked;
				}
				else
				{
					var obj = document.all("email");
					for( var x=0;x<obj.length;x++)
					{
						obj[x].checked = document.all("selectall").checked;
					}
				}
			}
		</script>
	</head>
	<body>
		<form action="javascript1.html" name="myform">
			<input type="checkbox" name="email"/>emailA<br/>
			<input type="checkbox" name="email"/>emailB<br/>
			<input type="checkbox" name="email"/>emailC<br/>
			<input type="checkbox" name="email"/>emailD<br/>
			<hr>
			<input type="checkbox" name="selectall" onclick="funAll()">selecAll
		</form>
	</body>
</html>

  

 

 

三、单选

 

<html>
	<head>
		<title>JavaScript3</title>
		<script type="text/javascript" language="javascript">
			function visitSex()
			{
				var obj = document.all("sex");
				if(obj.length == undefined )
				{
					alert(obj.value);
				}
				else
				{
					if(obj[0].checked)
					{
						alert("select is:"+obj[0].value);
					}else
					{
						alert("select is:"+obj[1].value);
					}
				}
			}
		</script>
	</head>
	<body>
		<input type="radio" name="sex" value="nan" checked="checked"/>man
		  
		<input type="radio" name="sex" value="nv" />woman
		<hr/>
		<input type="button" value="vistSex" onclick="visitSex()"/>
	</body>
</html>

  

 

 

 

posted on 2016-06-13 08:08  pony1223  阅读(185)  评论(0编辑  收藏  举报

导航