PHP+Mysql+jQuery实现发布微博程序

www.mgm4858.com

2018-10-20

HTMLformid=myformaction=method=posth3spanclass=counter140/span说说你正在做什么.../h3textareaname=saytxtid=saytxtclass=inputrows=2cols=40/textareapinputtype=imagesrc=images/=sub_btnalt=发布/spanid=msg/span/p/formdivclass=clear/divdivid=saywrapdivclass=saylistahref=#imgsrc=images/=//adivclass=saytxtpstrongahref=#Demo/a/strong发布的内容.../pdivclass=date/div/divdivclass=clear/div/div/div1、用户输入、鼠标离开输入框时,统计输入的字符数,并根据输入字数的不同而输出不同的样式(字体颜色)显示在页面上。 2、处理提交数据:当点击“发布”按钮时,显示等待图片,通过ajax想后台提交输入的数据,等待后台处理,并将处理结果输出给前端页面。 具体代码如下:functionrecount(){varmaxlen=140;varcurrent=maxlen-$(#saytxt).val().length;$(.counter).html(current);if(current1||currentmaxlen){$(.counter).css(color,#D40D12$(_btn).attr(disabled,disabled}else$(_btn).removeAttr(disabledif(current10)$(.counter).css(color,#D40D12elseif(current20)$(.counter).css(color,#5C0002else$(.counter).css(color,#cccccc}函数recount()完成了输入字符的统计,并根据输入的字符数,显示不同的字体颜色。

$(function(){$(#saytxt).bind(blurfocuskeydownkeypresskeyup,function(){recount();});$(#myform).submit(function(){varsaytxt=$(#saytxt).val();if(saytxt==){$(#msg).show().html(你总得说点什么吧.).fadeOut(1200);;returnfalse;}$(.counter).html(imgstyle=padding:8pxsrc=images/=正在处理.../$.ajax({type:POST,url:,data:saytxt=+saytxt,dataType:html,success:function(msg){if(parseInt(msg)!=0){$(#saywrap).prepend(msg);$(#saytxt).val(recount();}}});returnfalse;});});。