有没有办法使用存在的ajax代码传递下面表单的“日期”输入值?我意识到此刻我正在传递“彼得”和“谢菲尔德”,但我想将其切换为表格中输入的值:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript"
src=http://code.jquery.com/jquery-latest.js>
</script>
<script type="text/javascript">
// This functions starts the ajax to show the output from post.php
function StartAjax(ResultsId){
$.ajax({
type: "POST",
url: "postTest.php",
cache: false,
data: "name=Peter&location=Sheffield",
success: function(html, status){
$("#"+ResultsId).append(html);
$('#status').append(status);
}
});
}
</script>
</head>
<body>
<h1> Run Club</h1>
testing
<form>
date: <input type="text" name="date"><br>
</form>
<a href="#" onclick="StartAjax('ResultsId');">Click Here to see updates from postTest.php</a>
<div id="ResultsId"></div>
<div id="status"></div>
</body>
</html>
答案 0 :(得分:2)
您可以使用$('input[name="date"]').val()
所以你的数据值看起来像这样:
data: "name=Peter&location=Sheffield&date=" + $('input[name="date"]').val(),