我有一个 php 表单,当我直接打开它时可以正常工作。提交按钮将根据需要向多个表添加记录(使用 MySQL)。
但是当我将页面加载到另一个页面的div中时,点击提交按钮并没有添加记录。
这是JS
$('.tab_content').hide();
$('ul.tabs li:first').addClass("active").show();
$('.tab_content:first').show();
$('ul.tabs li').click(function () {
$('ul.tabs li').removeClass("active");
$(this).addClass("active");
$('.tab_content').hide();
var activeTab = $(this).find("a").attr("href");
$(activeTab).fadeIn(200, function () {
$(this).load($(this).attr("id") + ".php?" + Math.random());
});
return false;
});
例如加载 example.php,现在,如果文件中有一些提交表单,按钮不起作用,就像这样简单的 html
<form id="history" method="post" action="some_action.php">
<input type="text" name="test" id="test">
<input type="submit" value="submit" name="submit">
</form>
感谢回答)
最佳答案
如果你正确地获得了 href 值..那么:
改用 $.ajax();
试试这个:
<input type="button" id="do_submit" value="submit" name="submit">
然后:
$("#do_submit").click(function(){
$.ajax({
type: "POST",
url: yourURLvariable,
success: function(data){
$("#result_target").html(data);
}
});
});
关于javascript - 使用 .load() 时 Jquery 表单提交不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222443/