我一直在试图学习如何在PHP中使用jQuery AJAX。JQuery选择器似乎无法正常工作,除非在选择文档时
我的问题是,每当我选择除document
之外的任何其他元素,似乎没有任何工作。我想要的只是在按下提交按钮后无法加载页面,无济于事。
我试过使用jQuery而不是$,仍然没有运气。
我老实说不知道我在做什么,而且我试过寻找这个解决方案的小时数。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$("p").click(function() {
alert('test');
});
$("form").submit(function() {
alert('test');
return false;
});
</script>
<title>Insert title here</title>
</head>
<body>
<form action="process.php" method="post">
Inputs:<br />
<textarea rows="15" cols="60" id="input" name="input">Some text...
</textarea><br /><br />
Start:
<input type="text" id="start" name="start" />
End:
<input type="text" id="end" name="end" /><br />
<input type="submit" id="submit" name="submit" value="Submit">
</form>
<p id="output">Output: Some Random Text</p>
</body>
</html>
谢谢!现在正在工作。我可以问为什么选择文件仍然工作,即使它没有准备好? – Chad
@Chad - 没问题,很高兴我可以帮助:)您可以选择“文档”,因为它是在标记被解析和呈现之前首先创建的。这是有道理的,因为它是任何页面的根对象。 –