我整理了一个简化的问题示例。我的 HTML 代码如下:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script style="text/javascript">
$(document).ready(function(){
$('a.mylink').click(function(e){
//get the querystring
var href=$(this).attr('href');
var querystring=href.slice(href.indexOf('?')+1);
$.get('test_jq.php', querystring, function(data) {
//load the data
$('#mydiv').html(data);
});
//stop the link
return false;
});
$('#contact').submit(function() {
alert("you have submitted");
return false;
}); // end submit
});
</script>
</head>
<body>
<a class="mylink" href="test.php?info=A" >A</a>
<a class="mylink" href="test.php?info=B" >B</a>
<a class="mylink" href="test.php?info=C" >C</a>
<div id="mydiv">
Information loaded here.
</div>
</body>
</html>
这是 test.jq php 文件:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'GET' and isset($_GET["info"]) )
{
$info=$_GET["info"];
if($info=="A")echo "A";
elseif($info=="B")
{
echo '<form id="contact" method="post" action="email.php" >
<label>Name</label>
<input type="text">
<button type="submit">Submit</button>
</form>';
}
elseif($info=="C") echo "C";
}
Here is a working example:
http://www.scratchprogramming.org/test.php
本质上,我无法访问处理程序:
$('#contact').submit(function() {
alert("you have submitted");
return false;
}); // end submit
当我单击 B 链接然后提交表单时?
这是一个工作示例:
谢谢..吉利安