admin 发表于 2019-7-10 10:07:59

一个简单的留言板实现(jquery)

<p>先看一下效果图:</p><p><img src="http://img.domystery.com/Mys/M00/07/B9/cxwu3l0lRzeAerA2AAA6zKf2uM8339.png" title="1562724151552478.png" alt="image.png"/></p><p>实现方式比较简单,一个按钮触发留言窗体,窗体默认不显示;</p><p>然后指定位置展示;</p><p>之后输入,该填的填该写的写。点发布先进行数据检查,检查通过提交服务端数据处理。</p><p>页面:<br/></p><p>&lt;button class=&quot;lybtn&quot;&gt;留言&lt;/button&gt;</p><p>&lt;ul class=&quot;items&quot;&gt;&lt;/ul&gt;</p><p>&lt;div class=&quot;lybwindow&quot; style=&quot;display: none;&quot;&gt;</p><p>&nbsp; &nbsp; &lt;input type=&quot;text&quot; name=&quot;title&quot; id=&quot;title&quot; placeholder=&quot;请输入标题(1-60个字符)&quot; maxlength=&quot;60&quot; class=&quot;wenb&quot;&gt;</p><p>&nbsp; &nbsp; &lt;input type=&quot;text&quot; name=&quot;tel&quot; id=&quot;tel&quot; placeholder=&quot;请输入电话&quot; maxlength=&quot;11&quot; class=&quot;wenb&quot;&gt;</p><p>&nbsp; &nbsp; &lt;textarea name=&quot;content&quot; id=&quot;content&quot; cols=&quot;30&quot; rows=&quot;10&quot; class=&quot;kk&quot;&gt;&lt;/textarea&gt;</p><p>&nbsp; &nbsp; &lt;button class=&quot;publish&quot;&gt;发布&lt;/button&gt;</p><p>&lt;/div&gt;</p><p><img src="http://img.domystery.com/Mys/M00/07/B9/cxwu3l0lR7yAQqFwAABnKNuu9Ng714.png" title="1562724283265667.png" alt="image.png"/></p><p>JS部分:</p><p>&lt;script type=&quot;text/javascript&quot;&gt;</p><p>&nbsp; &nbsp; //点击时使发帖界面显示</p><p>&nbsp; &nbsp; $(&#39;.lybtn&#39;).click(function () {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; document.getElementsByClassName(&#39;lybwindow&#39;).style.display = &quot;block&quot;;</p><p>&nbsp; &nbsp; })</p><p><br/></p><p>&nbsp; &nbsp; $(&#39;.publish&#39;).click(function () {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; var title = $(&#39;#title&#39;).val();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; var content = $(&#39;#content&#39;).val();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; var tel = $(&#39;#tel&#39;).val();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (checkparam(title, content, tel)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&#39;请求接口&#39; + title + &#39; &#39; + content);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; })</p><p><br/></p><p>&nbsp; &nbsp; function requestdb(title, content, tel) {</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; function checkparam(title, content, tel) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (title == &#39;&#39;) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&#39;标题不能为空&#39;)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (title.length &gt; 60) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&#39;输入的标题过长!&#39;)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (content.length == 0) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&#39;内容不能为空&#39;)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if(!isphone(tel)){</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&#39;请输出有效的电话号码!&#39;)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; /*判断输入是否为合法的手机号码*/</p><p>&nbsp; &nbsp; function isphone(inputString)</p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; var partten = /^1\d{9}$/;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; var fl=false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if(partten.test(inputString))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; else</p><p>&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; }</p><p>&lt;/script&gt;</p><p>样式及头部:</p><p>&nbsp; &nbsp; &lt;script type=&quot;application/javascript&quot; src=&quot;./jquery.1.4.2-min.js&quot;&gt;&lt;/script&gt;</p><p>&nbsp; &nbsp; &lt;style type=&quot;text/css&quot;&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; * {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 12px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; .lybtn {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 70px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 30px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-radius: 20%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: fixed;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; right: 10%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; .publish {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 70px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 30px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-radius: 10%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-bottom: 5px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-left: 72%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; .lybwindow {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: fixed;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; right: 10%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bottom: 10%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* top: 0px; */</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border: 1px solid gray;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 300px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-radius: 20px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; .wenb {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 92%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 25px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-left: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: gray;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-radius: 20px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding-left: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; .kk {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-left: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 92%;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-radius: 20px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 15px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &lt;/style&gt;</p><p><br/></p><p><br/></p><p>OK,到这里一个简单的留言板出来了。</p>
页: [1]
查看完整版本: 一个简单的留言板实现(jquery)