日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
PHP+MySQL+jQuery實(shí)現(xiàn)發(fā)布微博程序——jQuery篇

我們?cè)赒Q個(gè)人中心或者新浪微博等網(wǎng)站上可以看到一個(gè)發(fā)表話題的應(yīng)用。該應(yīng)用實(shí)現(xiàn)了即時(shí)統(tǒng)計(jì)輸入字?jǐn)?shù),并且通過Ajax與后臺(tái)交互,將輸入內(nèi)容插入到話題列表中。本文講解***部分jQuery實(shí)現(xiàn)前端交互操作。

XHTML代碼

 
 
 
 
  1.       
  2.     

    140說說你正在做什么...

          
  3.           
  4.     

             

  5.                 
  6.              
  7.     

       
  8.    
   
  •        
  •                
  •                   
  •                      
  •             

    Demo發(fā)布的內(nèi)容...

                  
  •             
  •           
  •         
  •           
  •         
  •        
  •      
  •    
  •   

    XHTML是一個(gè)表單,里面有輸入框textarea,發(fā)布按鈕,還有一個(gè)統(tǒng)計(jì)輸入字?jǐn)?shù)的span#counter,和信息提示span#msg,在沒有輸入的情況下就提交則會(huì)提示用戶要求輸入內(nèi)容。

    CSS代碼

     
     
     
     
    1. h3{height:32px; line-height:32px; font-size:18px}   
    2. h3 span{float:right; font-size:32px; font-family:Georgia,serif; color:#ccc; overflow:hidden}   
    3. .input{width:594px; height:58px; margin:5px 0 10px 0; padding:4px 2px;    
    4. border:1px solid #aaa; font-size:12px; line-height:18px; overflow:hidden}   
    5. .sub_btn{float:right; width:94px; height:28px;}   
    6. #msg{color:#f30}   
    7. .clear{clear:both}   
    8. .saylist{margin:8px auto; padding:4px 0; border-bottom:1px dotted #d3d3d3}   
    9. .saylist img{float:left; width:50px; margin:4px}   
    10. .saytxt{float:right; width:530px; overflow:hidden}   
    11. .saytxt p{line-height:18px}   
    12. .saytxt p strong{margin-right:6px}   
    13. .date{color:#999}   

    jQuery

    先引入jquery庫和global.js文件:

     
     
     
     
    1.    
    2.   

    global.js要做的事有:

    1、用戶輸入、鼠標(biāo)離開輸入框時(shí),統(tǒng)計(jì)輸入的字符數(shù),并根據(jù)輸入字?jǐn)?shù)的不同而輸出不同的樣式(字體顏色)顯示在頁面上。

    2、處理提交數(shù)據(jù):當(dāng)點(diǎn)擊“發(fā)布”按鈕時(shí),顯示等待圖片,通過ajax想后臺(tái)提交輸入的數(shù)據(jù),等待后臺(tái)處理,并將處理結(jié)果輸出給前端頁面。

    具體代碼如下:

     
     
     
     
    1. function recount(){       
    2.    var maxlen=140;       
    3.    var current = maxlen-$('#saytxt').val().length;       
    4.    $('.counter').html(current);        
    5.  
    6.    if(current<1 || current>maxlen){           
    7.        $('.counter').css('color','#D40D12');           
    8.        $('input.sub_btn').attr('disabled','disabled');       
    9.    }       
    10.    else           
    11.       $('input.sub_btn').removeAttr('disabled');        
    12.    if(current<10)           
    13.       $('.counter').css('color','#D40D12');        
    14.    else if(current<20)           
    15.       $('.counter').css('color','#5C0002');        
    16.    else           
    17.       $('.counter').css('color','#cccccc');    
    18. }  

    函數(shù)recount()完成了輸入字符的統(tǒng)計(jì),并根據(jù)輸入的字符數(shù),顯示不同的字體顏色。

     
     
     
     
    1. $(function(){       
    2.    $('#saytxt').bind("blur focus keydown keypress keyup", function(){           
    3.        recount();       
    4.    });       
    5.    $("#myform").submit(function(){           
    6.        var saytxt = $("#saytxt").val();           
    7.        if(saytxt==""){               
    8.              $("#msg").show().html("你總得說點(diǎn)什么吧.").fadeOut(1200);;               
    9.              return false;           
    10.        }           
    11.        $('.counter').html('');           
    12.        $.ajax({              
    13.              type: "POST",              
    14.              url: "submit.php",              
    15.              data:"saytxt="+saytxt,              
    16.              dataType: "html",              
    17.              success: function(msg){                 
    18.                  if(parseInt(msg)!=0){                    
    19.                     $('#saywrap').prepend(msg);                    
    20.                     $('#saytxt').val('');                    
    21.                     recount();                
    22.                  }             
    23.         }           
    24.     });           
    25.     return false;       
    26.    });   
    27. });  

    提交數(shù)據(jù)給后臺(tái)后,由submit.php進(jìn)行處理。關(guān)于jQuery部分就到這里,后續(xù)會(huì)有關(guān)于后臺(tái)的處理程序,敬請(qǐng)關(guān)注。


    網(wǎng)站標(biāo)題:PHP+MySQL+jQuery實(shí)現(xiàn)發(fā)布微博程序——jQuery篇
    當(dāng)前URL:http://www.dlmjj.cn/article/ccsishi.html