一个简单的修复方法是更改查询名称;i、 e.来自page
到pageVal
.
<script>
jQuery(document).ready(function( $ ) {
$(\'.page-select\').change(function(){
var checkIndex = ( window.location.href || \'\' ).indexOf(\'?\');
if( checkIndex > -1 ){
var Link = window.location.href.substr(0, checkIndex-1);
$(location).attr(\'href\', Link+\'?pageVal=\'+$(\'.page-select\').val());
} else {
$(location).attr(\'href\', window.location.href+\'?pageVal=\'+$(\'.page-select\').val());
}
});
});
</script>
但我会用这个
<script>
jQuery(document).ready(function( $ ) {
$(\'.page-select\').change(function(){
var url = window.location.href || \'\',
has_q = ( url.indexOf( \'?\' ) > -1 );
if ( url.indexOf( \'?pageVal=\' ) > -1 ) {
url = url.replace( /\\?pageVal=\\d+/, \'?pageVal=\' + this.value );
} else if ( has_q && url.indexOf( \'&pageVal=\' ) > -1 ) {
url = url.replace( /&pageVal=\\d+/, \'&pageVal=\' + this.value );
} else {
url = url + ( has_q ? \'&\' : \'?\' ) + \'pageVal=\' + this.value;
}
window.location.href = url;
});
});
</script>
Additional Note
我也会改变
select
收件人:
<select id="news-posts-per-page" class="page-select"><?php
// List of "posts per page" options.
$per_pages = [ 10, 20, 30 ];
foreach ( $per_pages as $n ) {
$selected = selected( $n, $showposts, false );
printf( \'<option value="%d"%s>%d</option>\',
$n, $selected, $n );
}
?></select>