javascrip 高手

来源:百度知道 编辑:UC知道 时间:2024/07/07 10:52:24
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Expires" content="0">
<link type= "text/css" rel="stylesheet" href="<%=path%>/css/style.css">
<title>新建网页 1</title>
</head>

<body style="margin:0px">
<form name="form1" id="form1" method="post" action="<%=path%>/quickSearch.do" onsubmit="javascript:searchNow()">
<input type="hidden" name="view" value="result1">
<table border="0" width="100%" id="table1">
<tr><td colspan="3&quo

document.getElementsByName方法返回的是一个数组,就是所有name为keyword的标记 加个[0]就是数组的第一个

如果只有一个,也可以把name改成id id="keyword"
然后用 var obj = document.getElementById("keyword"); 来获取,效果是一样的

确定数组

因为document.getElementsByName(name)返回的是所有 “Name”为 name的元素的数组,也就是说Name属性是不唯一的。即使你的页面中只有一个name元素,返回的如仍然是数组,所以加个[0]表示取第一个。
如果不想拿数组,就用 document.getElementsById() id属性是唯一的,所以取到的就是一个元素。