js实现中英文模糊搜索

JavaScript053

js实现中英文模糊搜索,第1张

var Chinese = new RegExp('[\u4E00-\u9FA5]+') //中文

var Letter = new RegExp('[A-Za-z]+') //字母

      if (Chinese.test(this.systemInput)) {

        //中文搜索

        this.showOpList = this.List.filter(array => {

          if (array.title != undefined) {

            return array.title.indexOf(this.systemInput) >= 0

          }

          return false

        })

      }

if (Letter.test(this.systemInput)) {

        //字母搜索

        this.showOpList = this.List.filter(array => {

          let flag = false

          if (array.letter != undefined) {

            flag = array.letter.indexOf(this.systemInput) >= 0

          }

          if (array.spelling != undefined && !flag) {

            flag = array.spelling.indexOf(this.systemInput) >= 0

          }

          return flag

        })

      }

最简单的办法就是在你的所有中文页面上,一般在导航位置加一个英文页面首页的超链接。这样用户点英文那个链接就进入英文页面了。同样的,在所有的英文页面导航位置都加一个中文首页链接。推荐你用图片做这两个链接,这样不会因为用户没有装对应的语言系统而出现奇怪字符。比如欧美用户一般是不会装中文系统的,页面上有中文字符的时候必然显示为乱码。

网站目录当然要为中文和英文各建一个独立的目录,里面放置各自的页面了。

如果使用数据库的话,则思路是一样的。