怎么用PHP+Mysql+jQuery實(shí)現(xiàn)發(fā)布微博程序-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“怎么用PHP+Mysql+jQuery實(shí)現(xiàn)發(fā)布微博程序”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么用PHP+Mysql+jQuery實(shí)現(xiàn)發(fā)布微博程序”吧!

創(chuàng)新互聯(lián)建站主營(yíng)石柱土家族網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件定制開(kāi)發(fā),石柱土家族h5成都微信小程序搭建,石柱土家族網(wǎng)站營(yíng)銷(xiāo)推廣歡迎石柱土家族等地區(qū)企業(yè)咨詢(xún)
HTML

<form id="myform" action="" method="post">   <h4><span class="counter">140</span>說(shuō)說(shuō)你正在做什么...</h4>   <textarea name="saytxt" id="saytxt" class="input" rows="2" cols="40"></textarea>   <p>      <input type="image" src="images/btn.gif" class="sub_btn" alt="發(fā)布" />      <span id="msg"></span>   </p> </form> <p class="clear"></p> <p id="saywrap">    <p class="saylist">       <a href="#"><img src="images/user.gif" alt="" /></a>       <p class="saytxt">          <p><strong><a href="#">Demo</a></strong>發(fā)布的內(nèi)容...</p>           <p class="date"></p>       </p>       <p class="clear"></p>    </p> </p>

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

CSS

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

jQuery

先引入jquery庫(kù)和global.js文件:

<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/global.js"></script>

global.js文件:

global.js要做的事有:

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

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

具體代碼如下:

function recount(){ var maxlen=140; var current = maxlen-$('#saytxt').val().length; $('.counter').html(current); if(current<1 || current>maxlen){ $('.counter').css('color','#D40D12'); $('input.sub_btn').attr('disabled','disabled'); } else $('input.sub_btn').removeAttr('disabled'); if(current<10) $('.counter').css('color','#D40D12'); else if(current<20) $('.counter').css('color','#5C0002'); else $('.counter').css('color','#cccccc'); }

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

$(function(){ $('#saytxt').bind("blur focus keydown keypress keyup", function(){ recount(); });    $("#myform").submit(function(){ var saytxt = $("#saytxt").val(); if(saytxt==""){ $("#msg").show().html("你總得說(shuō)點(diǎn)什么吧.").fadeOut(1200);; return false; } $('.counter').html('<img  src="images/load.gif" alt="正在處理..." />'); $.ajax({   type: "POST",   url: "submit.php",   data:"saytxt="+saytxt,   dataType: "html",   success: function(msg){  if(parseInt(msg)!=0){ $('#saywrap').prepend(msg); $('#saytxt').val(''); recount(); }  }    }); return false; }); });

提交數(shù)據(jù)給后臺(tái)后,由submit.php進(jìn)行處理,關(guān)于后臺(tái)的處理程序,我在下一篇文章會(huì)重點(diǎn)講解,敬請(qǐng)關(guān)注。

到此,相信大家對(duì)“怎么用PHP+Mysql+jQuery實(shí)現(xiàn)發(fā)布微博程序”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!

網(wǎng)頁(yè)題目:怎么用PHP+Mysql+jQuery實(shí)現(xiàn)發(fā)布微博程序-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://bm7419.com/article32/hdssc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司虛擬主機(jī)、外貿(mào)網(wǎng)站建設(shè)移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)