Layui 태그 입력 상자 소개 inputTags

풀어 주다: 2020-02-07 17:31:33
앞으로
10248명이 탐색했습니다.

layui 프레임워크는 자체 모듈 사양을 사용하여 작성된 프런트 엔드 UI 프레임워크로 임계값이 매우 낮으며 즉시 사용할 수 있습니다. 이번 글에서는layui 프레임워크에서 사용되는 태그 입력 상자의 일종인 inputTags를 소개합니다.

Layui 태그 입력 상자 소개 inputTags

layui 태그 입력 상자 inputTags 스타일:

Layui 태그 입력 상자 소개 inputTags

디렉토리 구조:

Layui 태그 입력 상자 소개 inputTags

페이지 코드:

    inputTags  
  
로그인 후 복사

**inputTags.js**

/* * @Author: layui-2 * @Date: 2018-08-31 11:40:42 * @Last Modified by: layui-2 * @Last Modified time: 2018-09-04 14:44:38 */ layui.define(['jquery','layer'],function(exports){ "use strict"; var $ = layui.jquery,layer = layui.layer //外部接口 ,inputTags = { config: {} //设置全局项 ,set: function(options){ var that = this; that.config = $.extend({}, that.config, options); return that; } // 事件监听 ,on: function(events, callback){ return layui.onevent.call(this, MOD_NAME, events, callback) } } //操作当前实例 ,thisinputTags = function(){ var that = this ,options = that.config; return { config: options } } //字符常量 ,MOD_NAME = 'inputTags' // 构造器 ,Class = function(options){ var that = this; that.config = $.extend({}, that.config, inputTags.config, options); that.render(); }; //默认配置 Class.prototype.config = { close: false //默认:不开启关闭按钮 ,theme: '' //背景:颜色 ,content: [] //默认标签 ,aldaBtn: false //默认配置 }; // 初始化 Class.prototype.init = function(){ var that = this ,spans = '' ,options = that.config ,span = document.createElement("span"), spantext = $(span).text("获取全部数据").addClass('albtn'); if(options.aldaBtn){ $('body').append(spantext) } $.each(options.content,function(index,item){ spans +=''+item+''; // $(''); }) options.elem.before(spans) that.events() } Class.prototype.render = function(){ var that = this ,options = that.config options.elem = $(options.elem); that.enter() }; // 回车生成标签 Class.prototype.enter = function(){ var that = this ,spans = '' ,options = that.config; options.elem.focus(); options.elem.keypress(function(event){ var keynum = (event.keyCode ? event.keyCode : event.which); if(keynum == '13'){ var $val = options.elem.val().trim(); if(!$val) return false; if(options.content.indexOf($val) == -1){ options.content.push($val) that.render() spans =''+$val+''; options.elem.before(spans) } options.done && typeof options.done === 'function' && options.done($val); options.elem.val(''); } }) }; //事件处理 Class.prototype.events = function(){ var that = this ,options = that.config; $('.albtn').on('click',function(){ console.log(options.content) }) $('#tags').on('click','.close',function(){ var Thisremov = $(this).parent('span').remove(), ThisText = $(Thisremov).find('em').text(); options.content.splice($.inArray(ThisText,options.content),1) }) }; //核心入口 inputTags.render = function(options){ var inst = new Class(options); inst.init(); return thisinputTags.call(inst); }; exports('inputTags',inputTags); }).link('css/inputTags.css')
로그인 후 복사

layui에 대한 자세한 내용을 보려면 팔로우하세요.라위 사용법 튜토리얼칼럼.

위 내용은 Layui 태그 입력 상자 소개 inputTags의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:csdn.net
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!