我目前正在使用 jquery ui 选项卡和 ajax/post 提交而无需刷新页面。在一些指导下,我已经能够#wmd-preview
在单击下一步按钮时提交 div。问题是,当在各个选项卡中单击下一个按钮时,我还想同时提交其他字段。
单击下一步按钮时,如何提交不同选项卡中各种输入字段的输入值?例子
(对于一些测试,我目前有其他输入字段通过 keyup 和计时器设置提交)
JS- NEXT/Previous 按钮与提交/ajax 合并
<script>
var currentTab = 0;
$(function() {
var $tabs = $('#tabs').tabs({
disabled: [0, 1, 2]
, select: function() {
if (currentTab == 0) {
$.ajax({
type: "POST",
url: "test1.php",
data: { "wmdVal": $("#wmd-preview").html() },
success: function(result) {
$('#wmd_result').html( $('#resultval', result).html());
}
});
}
}
, show: function(event, ui) {
currentTab = ui.index;
}
});
$(".ui-tabs-panel").each(function(i) {
var totalSize = $(".ui-tabs-panel").size() - 1;
if (i != totalSize) {
next = i + 2;
$(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page »</a>");
}
if (i != 0) {
prev = i;
$(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>« Prev Page</a>");
}
});
$('.next-tab, .prev-tab').click(function() {
var tabIndex = $(this).attr("rel");
$tabs.tabs('enable', tabIndex)
.tabs('select', tabIndex)
.tabs("option","disabled", [0, 1]);
return false;
});
});
</script>
HTML
<div id="tab-1" class="ui-tabs-panel ui-tabs-hide">
<label for="title">Title</label>
<input type="text" id="title" name="title" size="60" autocomplete="off" value="<? $title ?>"/>
<div id="wmd-editor" class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea id="wmd-input" name="wmd-input"></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd_result"></div>
<div id="title_input"style="padding:20px;"></div>
</div>
<div id="tab-2" class="ui-tabs-panel ui-tabs-hide">
<label for="name">Name</label>
<input type="text" id="name" name="name" size="60" autocomplete="off" value="<? $name ?>"/>
<div id="name_input"></div>
</div>
PHP
<?
if (isset($_POST['title'])){
$wmdVal = $_POST['title'];
echo ('<div id="title_input"><span id="resultval"><h2>Title Echo result:</h2>'.$wmdVal.'</span></div>');
}
if (isset($_POST['wmdVal'])){
$wmdVal = $_POST['wmdVal'];
echo ('<div id="wmd_result"><span id="resultval"><h2>Description Echo result:</h2>'.$wmdVal.'</span></div>');
}
if (isset($_POST['name'])){
$name = $_POST['name'];
echo ('<div id="name_input"><span id="resultval"><h2>Description Echo result:</h2>'.$name.'</span></div>');
}
?>