【发布时间】:2020-06-06 18:34:56
【问题描述】:
在下面的代码中,我试图将用户输入的所有标记传递到另一个页面以执行,但只有在表中输入的第一个标记的值是发送的。有没有办法发送所有的值输入的标记,而不仅仅是第一个值;
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function send(){
var marks=document.getElementById("marks").value;
var xmlhttp=new XMLHttpRequest()
xmlhttp.onreadystatechange=function()
{
if(this.readyState==4 &&this.status==200)
{
document.getElementById("result").innerHTML=this.responseText;
}
};
xmlhttp.open('GET','mark.php?marks='+marks,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table>
<tr>
<td>name</td>
<td>marks</td>
</tr>
<tr>
<td><input type="text" ></td>
<td><input type="number" id ="marks"></td>
</tr>
<tr>
<td><input type="text" ></td>
<td><input type="number" id ="marks"></td>
</tr>
<tr>
<td><input type="text" ></td>
<td><input type="number" id ="marks"></td>
</tr>
</table>
<button onlick="send()" >submit</button>
<div id='result'><p></p><div>
</body>
</html>
【问题讨论】:
-
ID属性必须是唯一的 - 所以拥有两个或更多marks是不正确的
标签: javascript php ajax xmlhttprequest