$(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){ $(".enter.addkeyWord").show(); $(".addKeyWord").hide(); $(".showKeyWord").hide(); } else { $(".enter.addkeyWord").hide(); $(".showKeyWord").show(); $(".addKeyWord").show(); } } hasWords(); // 添加按钮 $(".addKeyWord i").on('click',function(){ window.location.href="/front/wx_dataExport/buyerInput"; }); // 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮 $('.addkeyWord input.enterOne').on('input', function() { var buttonDOM = $(this).siblings().find('button')[0] if ($(this).val().length >= 1) { buttonDOM.style.opacity = 1 buttonDOM.removeAttribute("disabled") } else { buttonDOM.style.opacity = .5 buttonDOM.setAttribute("disabled", true) } }) // 添加 按钮的点击事件 $('.addkeyWord .btn .save-btn').on('click', function(){ var keyWord = $('.addkeyWord input.enterOne').val() keyWord = keyWord.replace(/\s/g,""); if (keyWord.length > 50) { // var s = keyWord.slice(0,49); // $('.addkeyWord input.enterOne').val(s); weui.toast('采购单位不能超过50字', { duration: 2000, className: 'text-overflow100', callback: function(){} }); return } buyerArr.push(keyWord); localStorage.setItem("buyer", buyerArr); var html = `
  • ${ keyWord }

    ${ keyWord }
  • ` $('.showKeyWord > ul').prepend(html) // 隐藏 $(".enter.addkeyWord").hide(); $(".showKeyWord").show(); $(".addKeyWord").show(); $('.enter.addkeyWord > input').val('') var buttonDOM = $('.enter.addkeyWord .btn button')[0] buttonDOM.style.opacity = .5 buttonDOM.setAttribute("disabled", true) }) // 编辑 $(".showKeyWord").on('click', '.editKeyWord',function(e){ let oSpan = e.target.parentNode.nextElementSibling.children[0]; let val = $(oSpan).val(); $(this).parent().hide(); $(this).parent().siblings().show().parent().siblings().children('.modify').hide().siblings('.one').show() $(oSpan).val('').focus().val(val); $(".addKeyWord").hide(); }) // 编辑 删除 $('.showKeyWord').on('click', '.deleteKey', function(e) { var buyer = $(this).parent().prev().find('.key').text(); buyerArr.splice($.inArray(buyer, buyerArr),1); localStorage.buyer = buyerArr.toString(); $(this).parents('li').remove(); $(".addKeyWord").show(); hasWords() // console.log('删除附加词:',$(this).parent().find('span').text()) }) // 编辑 确定 $('.showKeyWord').on('click', '.ascertainKey', function(e) { var keyWord = $(this).siblings('textarea').val(); var buyer = $(this).parent().prev().find('.key').text(); keyWord = keyWord.replace(/\s/g,""); if (keyWord.length < 1) { weui.toast('采购单位不能为空', { duration: 2000, className: 'text-overflow100', callback: function(){ } }); return }else if($(this).parent().find("textarea").val().length > 50){ // var s = $(this).parent().find("span").text().slice(0,49); // $(this).parent().find("span").text(s); weui.toast('采购单位不能超过50字', { duration: 2000, className: 'text-overflow100', callback: function(){} }); return }else{ for(var i in buyerArr){ if(buyerArr[i] === buyer){ buyerArr[i] = keyWord; } } localStorage.buyer = buyerArr.toString(); $(this).parent().siblings().find('.key').text(keyWord) $(this).parent().hide().siblings().show() } $(".addKeyWord").show(); }) //去空格方法 String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ' '); } $(".close").on("click", function () { history.back(); }) });