微信小程序搜索框樣式并實現(xiàn)跳轉(zhuǎn)到搜索頁面(小程序搜索功能)
更新時間:2020年03月10日 15:32:58 作者:a_靖
這篇文章主要介紹了微信小程序搜索框樣式并實現(xiàn)跳轉(zhuǎn)到搜索頁面(小程序搜索功能),需要的朋友可以參考下
上效果圖:
一:搜索框功能實現(xiàn)
1.在首頁做一個搜索框的樣式并實現(xiàn)跳轉(zhuǎn)到搜索頁面
<view class='page_row' bindtap="suo"> <view class="search"> <view class="df search_arr"> <icon class="searchcion" size='20' type='search'></icon> <input class="" disabled placeholder="請輸入關(guān)鍵字" value="{{searchValue}}"/> </view> </view> <view class='sousuo'>搜索</view> </view>
.search{ width: 80%; } .search_arr { border: 1px solid #d0d0d0; border-radius: 10rpx; margin-left: 20rpx; } .search_arr input{ margin-left: 60rpx; height: 60rpx; border-radius: 5px; } .bc_text { line-height: 68rpx; height: 68rpx; margin-top: 34rpx; } .sousuo { margin-left: 15rpx; width: 15%; line-height: 150%; text-align: center; border: 1px solid #d0d0d0; border-radius: 10rpx; } .page_row{ display: flex; flex-direction: row } .searchcion { margin: 10rpx 10rpx 10rpx 10rpx; position: absolute; left:25rpx; z-index: 2; width: 20px; height: 20px; text-align: center; }
js.點擊跳轉(zhuǎn)到搜索的頁面
suo: function (e) { wx.navigateTo({ url: '../search/search', }) },
2.搜索頁面實現(xiàn)搜索功能
<!--pages/search/search.wxml--> <view class="search page_row"> <input class="df_1" placeholder="請輸入你有搜索的內(nèi)容" value="{{searchValue}}" bindinput="searchValueInput" /> <button bindtap="suo" data-id='1'> 媒婆 </button> <button bindtap="suo" data-id='2'> 單身 </button> </view> <view class="search_no" wx:if="{{!centent_Show}}"> <text>很抱歉,沒有找到您要搜索的資料/(ㄒoㄒ)/~~</text> </view> <import src="../index/card/card.wxml" /> <template is="nanshen_card" data="{{nanshen_card,img}}" />
var app = getApp(); var searchValue ='' // pages/search/search.js Page({ data: { centent_Show: true, searchValue: '', img: '', nanshen_card:'' }, onLoad: function () { }, searchValueInput: function (e) { var value = e.detail.value; this.setData({ searchValue: value, }); if (!value && this.data.productData.length == 0) { this.setData({ centent_Show: false, }); } }, suo:function(e){ var id= e.currentTarget.dataset.id var program_id = app.program_id; var that = this; wx.request({ url: 'aaa.php',//這里填寫后臺給你的搜索接口 method: 'post', data: { str: that.data.searchValue, program_id: program_id, style:id }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { if(res.data.length ==0){ that.setData({ centent_Show: false, }); } that.setData({ nanshen_card: res.data, }); }, fail: function (e) { wx.showToast({ title: '網(wǎng)絡(luò)異常!', duration: 2000 }); }, }); } });
/* pages/search/search.wxss */ @import "../index/card/card"; .searchcion{ width: 24px; height: 24px; text-align: center; margin-top: 5rpx } .search{ padding: 1% 3%; background: #D0D0D0; } .search input{ width: 85%; border-radius: 5px; background: #fff; border: none; font-size: 12px; padding:1% 2.5%; margin-right: 5px; } .search button{ line-height:30px; text-align: center; border: none; font-size: 28rpx; background: white }
php實現(xiàn)代碼
<?php header("Content-Type:text/html;charset=utf8"); header("Access-Control-Allow-Origin: *"); //解決跨域 header('Access-Control-Allow-Methods:POST');// 響應(yīng)類型 header('Access-Control-Allow-Headers:*'); // 響應(yīng)頭設(shè)置 $link=mysql_connect("localhost","root","root"); mysql_select_db("shige", $link); //選擇數(shù)據(jù)庫 mysql_query("SET NAMES utf8");//解決中文亂碼問題 $str = $_POST['str']; //SQL查詢語句 SELECT * FROM 表名 LIKE 模糊搜索的變量 $q="SELECT * FROM curriculum WHERE CONCAT_WS('',school,college,major,mtype,title) LIKE '%{$str}%'"; $rs = mysql_query($q); //獲取數(shù)據(jù)集 if(!$rs){die("數(shù)據(jù)庫沒有數(shù)據(jù)!");} //循環(huán)讀取數(shù)據(jù)并存入數(shù)組對象 $dlogs;$i=0; while($row=mysql_fetch_array($rs)) { $dlog['title']= $row["title"]; $dlog['mtype']= $row["mtype"]; $dlog['name']= $row["name"]; $dlog['mfile']= $row["mfile"]; $dlog['myear']= $row["myear"]; $dlog['school']= $row["school"]; $dlog['college']= $row["college"]; $dlog['major']= $row["major"]; $dlog['time']= $row["time"]; $dlogs[$i++]=$dlog; } //以json格式返回html頁面 echo urldecode(json_encode($dlogs)); ?>
總結(jié)
到此這篇關(guān)于微信小程序搜索框樣式并實現(xiàn)跳轉(zhuǎn)到搜索頁面(小程序搜索功能)的文章就介紹到這了,更多相關(guān)微信小程序搜索內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS+DIV+CSS實現(xiàn)的經(jīng)典標簽切換效果代碼
這篇文章主要介紹了JS+DIV+CSS實現(xiàn)的經(jīng)典標簽切換效果代碼,涉及JavaScript基于鼠標事件針對頁面元素動態(tài)變換的實現(xiàn)技巧,頁面美觀實用,需要的朋友可以參考下2015-09-09js中symbol類型以及symbol的三大應(yīng)用場景詳解
Symbol是ES6新推出的一種基本類型,它表示獨一無二的值,它可以接受一個字符串作為參數(shù),帶有相同參數(shù)的兩個Symbol值不相等,這個參數(shù)只是表示Symbol值的描述而已,下面這篇文章主要給大家介紹了關(guān)于js中symbol類型以及symbol的三大應(yīng)用場景,需要的朋友可以參考下2022-09-09使用CSS+JavaScript或純js實現(xiàn)半透明遮罩效果的實例分享
這篇文章主要介紹了使用CSS+JavaScript或純js實現(xiàn)半透明遮罩效果的實例分享,編寫半透明遮罩層時要注意定位問題、不要滿屏遮罩,需要的朋友可以參考下2016-05-05純JavaScript基于notie.js插件實現(xiàn)消息提示特效
這篇文章主要介紹了純JavaScript基于notie.js插件實現(xiàn)消息提示特效,可以制作Alert提示框,確認框和帶輸入的消息框,感興趣的小伙伴們可以參考一下2016-01-01