1. 在窗口滚动时自动加载内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
var loading
= false ; $(window).scroll( function (){ if ((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){ if (loading
== false ){ loading
= true ; $( '#loadingbar' ).css( "display" , "block" ); $.get( "load.php?start=" +$( '#loaded_max' ).val(), function (loaded){ $( 'body' ).append(loaded); $( '#loaded_max' ).val(parseInt($( '#loaded_max' ).val())+50); $( '#loadingbar' ).css( "display" , "none" ); loading
= false ; }); } } }); $(document).ready( function ()
{ $( '#loaded_max' ).val(50); }); |
2.预防对表单进行多次提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
$(document).ready( function ()
{ $( 'form' ).submit( function ()
{ if ( typeof jQuery.data( this , "disabledOnSubmit" )
== 'undefined' )
{ jQuery.data( this , "disabledOnSubmit" ,
{ submited: true }); $( 'input[type=submit],
input[type=button]' , this ).each( function ()
{ $( this ).attr( "disabled" , "disabled" ); }); return true ; } else { return false ; } }); }); |
3.返回页面顶部
1
2
3
4
5
6
7
8
|
// Back To Top $(document).ready( function (){ $( '.top' ).click( function ()
{ $(document).scrollTo(0,500); }); }); //Create a link defined with the class .top <a href= "#" class= "top" >Back
To Top</a> |