我每个页面都有一个问题。我使用每页的项目(60件),但我想选择一个金额。
<script type="text/javascript">
$(document).ready(function(){
function loading_show(){
$('#loading').html("<img src='./img/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}
function loadData(page){
loading_show();
$.ajax
({
type: "POST",
url: "load_data.php",
data: "page="+page,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
//Put code here like so
$('html, body').animate({ scrollTop: 0 }, 1000);
});
}
});
}
loadData(1); // For first time page load default results
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});
$("#aantal").live('change',function(){
var aantal = $('#aantal :selected').val();
alert('Aantal per pagina:'+aantal);
// alert('hello');
});
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});
</script>
这是选择框:
<select name='aantal' class='aantal' id='aantal'>
<option value='10'>10</option>
<option value='60' selected='selected'>60</option>
<option value='1000'>all</option>
</select>
这是加载功能。
<?php
if($_POST['page'])
{
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = ($_POST["aantal"] <> "" && is_numeric($_GET["aantal"]) ) ? intval($_GET["aantal"]) : 60;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
include"db.php";
?>
当我这样做时,我会收到警报框。但是,我如何选择每页的金额?
答案 0 :(得分:1)
您需要将选择框的值发送到php加载函数。只需修改data
密钥即可将其包含在内
$.ajax
({
type: "POST",
url: "load_data.php",
data: {"page": page, "aantal": $('#aantal').val()}
...