$(function(){ $('.knowBtn').on('click',function(){ $(".problemPop").hide() }) $(".problem").on('click',function(){ $(".problemPop").css("display",'flex'); }) function hasWords () { var showKeyWordLength = $(".showKeyWord ul").find('li').length; if(showKeyWordLength === 0){ $(".addkeyWord").show(); $('.addKeyWord').hide(); } else { $(".addkeyWord").hide(); $('.addKeyWord').show(); } } hasWords() // 添加按钮 $(".addKeyWord i").on('click',function(){ $(".addkeyWord").show(); $(".addKeyWord").hide(); $(".addkeyWord input").focus(); $('.showKeyWord').find('.one').show(); $('.showKeyWord').find('.modify').hide(); }) // 输入框自适应高度 $('textarea').each(function(i,dom){ // console.log(i,dom) dom.style.height = dom.scrollHeight +'px'; }) $("textarea").on("input", function() { this.style.height = 'auto'; this.style.height = this.scrollHeight + "px"; }) // 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮 $('.addkeyWord input.enterOne').on('input', function() { var buttonDOM = $(this).siblings().find('button')[1] if ($.trim($(this).val()).length >= 1) { buttonDOM.style.opacity = 1 buttonDOM.removeAttribute("disabled") } else { buttonDOM.style.opacity = .5 buttonDOM.setAttribute("disabled", true) } }) // 添加 按钮的点击事件 $('.addkeyWord .btn button:nth-child(2)').on('click', function(){ var timestamp = new Date().getTime();//动态生成不同的id,因为id唯一不能重复,所以 用时间戳 代替 防止重复 var keyWord = $.trim($('.addkeyWord input.enterOne').val()); if(keyWord==""&&keyWord.length==0){ weui.toast('附加词不能为空', { duration: 2000, className: 'custom-toast', callback: function () { console.log('close') } }); return } _addindex = 0; if($(".showKeyWord li").length>0){ _addindex = Number($(".showKeyWord li:first").find(".editKeyWord").attr("dataIndex")) + Number(1); } if(addkws_arr[keyWord]!=undefined){ weui.toast('您设置的附加词已存在,请调整后再添加。', { duration: 2000, className: 'custom-toast', callback: function () { console.log('close') } }); return } //保存新附加词 _addkws = keyWord; saveSession("",_addindex); var html = `
  • ${ keyWord }

  • ` $('.showKeyWord > ul').prepend(html) // 隐藏 $(".addkeyWord").hide(); $('.showKeyWord').show(); $('.addKeyWord').show(); $('.enter.addkeyWord > input').val('') var buttonDOM = $('.enter.addkeyWord .btn button')[1] buttonDOM.style.opacity = .5 buttonDOM.setAttribute("disabled", true) }) // 编辑 $(".showKeyWord").on('click', '.editKeyWord',function(e){ _addindex = Number($(this).attr("dataindex")); $('.enter.addkeyWord').hide() $('.addKeyWord').hide() let oSpan = $(this).parent().siblings().children('textarea'); let val = $(oSpan).val() $(this).parent().siblings().show().parents('li').siblings().children('.modify').hide().siblings('.one').show() $(oSpan).val('').focus().val(val) $(this).parent().hide() $(this).parent().siblings().css('display','block') }) // 编辑 删除 $('.showKeyWord').on('click', '.deleteKey', function(e) { var jQueryDOM = $(this).parents('li'); _addkws = $.trim($(this).siblings('textarea').val()); var _index = $('.showKeyWord li').length - $(this).parent().parent("li").index() -1; weui.confirm('确定要删除附加词?', { buttons: [{ label: '取消', type: 'default', onClick: function () { console.log('不删了') } }, { label: '确定', type: 'primary', onClick: function () { jQueryDOM.remove(); hasWords(); saveSession("D",_addindex,_index); } }] }); }) // 编辑 确定 $('.showKeyWord').on('click', '.ascertainKey', function(e) { var keyWord = $.trim($(this).siblings('textarea').val()); var _index = $('.showKeyWord li').length - $(this).parent().parent("li").index() -1; if(keyWord.length==0){ weui.toast('附加词不能为空', { duration: 2000, className: 'custom-toast', callback: function () { console.log('close') } }); }else if(keyWord.length > 20){ weui.toast('每组附加词不能超过20字', { duration: 2000, className: 'custom-toast', callback: function () { console.log('close') } }); }else{ if(addkws_arr[keyWord]!=undefined&&addkws_arr[keyWord]!=_addindex){ weui.toast('您设置的附加词已存在,请调整后再添加。', { duration: 2000, className: 'custom-toast', callback: function () { console.log('close') } }); return } $('.addKeyWord').show() _addkws = keyWord; saveSession("",_addindex,_index); $(this).parent().siblings().find('.key').text(keyWord) $(this).parent().hide().siblings().show() } }) //防止键盘把当前输入框给挡住 var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 if(isAndroid){ //防止键盘把当前输入框给挡住 window.addEventListener('resize', function () {    if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {    window.setTimeout(function () {           document.activeElement.scrollIntoViewIfNeeded(); }, 0); } }) } })