收藏
回答

两个input保存只能保存一个值怎么办??

问题模块 框架类型 问题类型 终端类型 微信版本 基础库版本
框架 小程序 Bug 工具 6.6.6 2.0.0


这个是首页代码,,


保存后查看,下面的两个值是一样的。。因为这个原来是两个输入框的,我复制了一个输入框的代码,js代码也添加了一份。怎么破,求解啊

最后一次编辑于  2018-06-30  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答

10 个回答

  • 人生若只如初见
    人生若只如初见
    2018-06-30

    你代码图片 那么小 根本看不清   .....

    2018-06-30
    赞同
    回复 9
    • .
      .
      2018-06-30
      <view class="newNotePad">
          <image style="width:30px;height:30px; float:left; margin-left:10px; display:{{deleteDisplay}};" src="../../pages/images/delete.png" bindtap="deleteNotePad"></image>
          <image style="width:30px;height:30px; margin-right:10px;background-color:green;" src="../../pages/images/new.png" bindtap="newNotePad"></image>
      </view>
      <view class="alert" style="display:{{alertDisplay}}">输入框不能为空!</view>
      <form bindsubmit="noteSubmit" bindreset="noteReset">
          <view class="title"  style="opacity:{{titleBorderOpacity}}">
              <input style="opacity:{{titleInputOpacity}}" name="title" type="text" value="{{titleValue}}" disabled="{{titleDisabled}}"
              placeholder="备注" maxlength="18" bindfocus="titleInputBindfocus"></input>
          </view>
          <view class="content" style="opacity:{{contentBorderOpacity}};">
              <textarea style="opacity:{{contentTextAreaOpacity}};height:{{contentTextAreaHeight}}px;" name="content" value="{{contentValue}}"
              disabled="{{contentDisabled}}" placeholder="1" bindfocus="contentTextareaBindfocus"></textarea>
          </view>
          <view class="passnum" style="opacity:{{passnumBorderOpacity}};">
              <input style="opacity:{{passnumTextAreaOpacity}}" name="passnum" value="{{passnumValue}}"
              disabled="{{passnumDisabled}}"  bindfocus="passnumTextareaBindfocus"></input>
          </view>   
          <view class="btnNote {{display_new?'display':'display_none'}}">
              <view style="border:1px solid green;border-radius: 4px; width:96%; margin-left: 2%; opacity:{{btnSaveBorderOpacity}} ">
                  <button style="background-color:green;height:40px;line-height:40px; color:white; " disabled="{{saveBtnDisabled}}"
                  formType="submit" bindtap="saveNotePad">{{btnTxt}}</button>
              </view>    
          </view>
           
      </form>
      <view class="bottomBar" style="display:flex;">
          <navigator url="../../pages/index/index?state=new" redirect>
              <view style="text-align:center; width:{{tabWidth}}px;">
                  <view><image style="width:25px; height:25px;" src="../../pages/images/writeSelected.png"></image></view>
                  <view><text style="font-size:10pt; color:#006633">记录事件</text></view>
              </view>
          </navigator>
          <navigator url="../../pages/checkNote/checkNote" redirect>
              <view style="text-align:center; width:{{tabWidth}}px;" >
                  <view><image style="width:25px; height:25px;" src="../../pages/images/search.png"></image></view>
                  <view><text style="font-size:10pt;">查看日记</text></view>
              </view>
          </navigator>
      </view>


      2018-06-30
      赞同
      回复
    • 人生若只如初见
      人生若只如初见
      2018-06-30回复.

      js  代码 也发一下  这部分 看着 没什么 问题  不过 不太清楚 为什么用focus事件

      2018-06-30
      赞同
      回复
    • .
      .
      2018-06-30回复人生若只如初见
      var id,state;
      Page({
        data:{   
          tabWidth:'',
          titleDisabled:true,
          contentDisabled: true,
          passnumDisabled: true,
          saveBtnDisabled:true,
          inputValue:'',
          contentValue: '',
          passnumValue: '',
          display_new:true,
          display_look:false,
          updateBtnDisabled:false,
          resaveBtnDisabled:true,
          titleBorderOpacity:0.4,
          titleInputOpacity:0.4,
          contentBorderOpacity:0.4,
          contentTextAreaOpacity: 0.4,
          passnumBorderOpacity: 0.4,
          passnumTextAreaOpacity: 0.4,
          btnSaveBorderOpacity:0.4,
          btnUpdateOpacity:1,
          btnResaveOpacity:0.4,
          btnTxt:'保存',
          alertDisplay:'none',
          contentTextAreaHeight: '',
          passnumTextAreaHeight: '',
          deleteDisplay:'none'
        },
        newNotePad:function(e){
          wx.redirectTo({
            url: '../../pages/index/index?state=new'
          })
        },
        deleteNotePad:function(){
          wx.showModal({
            title:'删除',
            content:'确认删除这条记录吗?',
            success:function(res){
              if(res.confirm){
                console.log('确定')
                var title = wx.getStorageSync('title'), content = wx.getStorageSync('content'), passnum = wx.getStorageSync('passnum'),dateNow=wx.getStorageSync('dateNow');
                console.log(title + content + passnum+dateNow+'   '+id)
                title.splice(id-1,1)
                content.splice(id - 1, 1)
                passnum.splice(id - 1, 1)
                dateNow.splice(id-1,1)         
                try{
                  wx.setStorageSync('title', title)    
                  wx.setStorageSync('content', content)
                  wx.setStorageSync('passnum', passnum)
                  wx.setStorageSync('dateNow', dateNow)
                  wx.showToast({
                    title:'删除成功'
                  })
                  wx.redirectTo({
                    url: '../../pages/checkNote/checkNote',
                    success: function(res){
                      // success
                    },
                    fail: function() {
                      // fail
                    },
                    complete: function() {
                      // complete
                    }
                  })
                }catch(e){
                  console.log(e.message)
                }
                 
              }else{
                console.log('取消')
              }
            }
          })
        },
        noteSubmit:function(e){
          if(state=='new'){//如果点击了新建
            console.log("现在点击的功能是保存")
            if (e.detail.value.title.length == 0 && e.detail.value.content.length == 0 && e.detail.value.passnum.length == 0){
              this.setData({
                alertDisplay:'block'
              })
            }else{           
              this.setData({
                titleDisabled:true,
                contentDisabled: true,
                passnumDisabled: true,
                saveBtnDisabled:true,
                titleBorderOpacity:0.6,
                titleInputOpacity:0.6,
                contentBorderOpacity:0.6,
                contentTextAreaOpacity: 0.6,
                passnumBorderOpacity: 0.6,
                passnumTextAreaOpacity: 0.6,
                btnSaveBorderOpacity:0.6
              })   
              var title=wx.getStorageSync('title') || [];
              var content = wx.getStorageSync('content') || [];
              var passnum = wx.getStorageSync('passnum') || [];
              var date=new Date();
              var year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
              var hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds();
              var dateNow=year+"年"+month+"月"+day+"日 "+hour+"时"+minute+"分"+second+"秒"
              var dateNowInfo=wx.getStorageSync('dateNow') || [];
              title.unshift(e.detail.value.title);
              content.unshift(e.detail.value.content);
              passnum.unshift(e.detail.value.passnum);
              dateNowInfo.unshift(dateNow);
              try{
                wx.setStorageSync('title', title)    
                wx.setStorageSync('content', content)
                wx.setStorageSync('passnum', passnum)
                wx.setStorageSync('dateNow', dateNowInfo)
                wx.showToast({
                  title:'保存成功'
                })
              }catch(e){
                console.log(e.message)
              }
              
            }
          }
          if(typeof(id)=="string"){
            console.log("现在点击的功能是重新保存")
            if (e.detail.value.title.length == 0 && e.detail.value.content.length == 0 && e.detail.value.passnum.length == 0){
              this.setData({
                alertDisplay:'block'
              })
            }else{
              var title = wx.getStorageSync('title') || [], content = wx.getStorageSync('content') || [], passnum = wx.getStorageSync('passnum') || [],dateNowInfo=wx.getStorageSync('dateNow') || [];
                var date=new Date();
                var year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
                var hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds();
                var dateNow=year+"年"+month+"月"+day+"日 "+hour+"时"+minute+"分"+second+"秒"
                console.log(title[id - 1] + ' ' + content[id - 1] + ' ' + passnum[id - 1] +' '+dateNow[id-1])
                title.splice(id-1,1,e.detail.value.title);
                content.splice(id - 1, 1, e.detail.value.content);
                passnum.splice(id - 1, 1, e.detail.value.passnum);
                dateNowInfo.splice(id-1,1,dateNow)
                try{
                  wx.setStorageSync('title', title)    
                  wx.setStorageSync('content', content)
                  wx.setStorageSync('passnum', passnum)
                  wx.setStorageSync('dateNow', dateNowInfo)
                  wx.showToast({
                    title:'保存成功'
                  })
                }catch(e){
                  console.log(e.message);
                }
                console.log(title[id - 1] + ' ' + content[id - 1] + ' ' + passnum[id - 1] +' '+dateNow[id-1]);
            }     
          }     
        },
        noteReset:function(){
       
        },
        titleInputBindfocus:function(){
          this.setData({
            alertDisplay:'none'
          })
          if(typeof(id)=="string"){
            this.setData({
              titleBorderOpacity:1,
              titleInputOpacity:1,
              contentBorderOpacity:1,
              contentTextAreaOpacity: 1,
              passnumBorderOpacity: 1,
              passnumTextAreaOpacity: 1,          
            })
          }

        },

      (第二段替换词)

      })


      2018-06-30
      赞同
      回复
    • .
      .
      2018-06-30回复人生若只如初见
      contentTextareaBindfocus:function(){
        this.setData({
          alertDisplay:'none'
        })
        if(typeof(id)=="string"){
          this.setData({
            titleBorderOpacity:1,
            titleInputOpacity:1,
            contentBorderOpacity:1,
            contentTextAreaOpacity: 1,
            passnumBorderOpacity: 1,
            passnumTextAreaOpacity: 1,
            alertDisplay:'none'
          })
        }
      },
      passnumTextareaBindfocus: function () {
        this.setData({
          alertDisplay: 'none'
        })
        if (typeof (id) == "string") {
          this.setData({
            titleBorderOpacity: 1,
            titleInputOpacity: 1,
            contentBorderOpacity: 1,
            contentTextAreaOpacity: 1,
            passnumBorderOpacity: 1,
            passnumTextAreaOpacity: 1,
            alertDisplay: 'none'
          })
        }
      },
      saveNotePad:function(){//保存按钮
        if(state=="new"){
          this.setData({
            titleDisabled:false,
            contentDisabled:false,
            passnumDisabled: false,
            saveBtnDisabled:false,
              
          })
        }
        if(typeof(id)=="string"){           
            this.setData({
              titleBorderOpacity:0.4,
              contentBorderOpacity: 0.4,
              passnumBorderOpacity: 0.4,
            })
        }    
      },
      onLoad:function(options){  
        console.log(wx.getStorageSync('title'))
        console.log(wx.getStorageSync('content'))
        console.log(wx.getStorageSync('passnum'))
        console.log(wx.getStorageSync('dateNow'))
        console.log("index:"+options.id);
        var that=this;
        state=options.state
        if(state=='new'){
          this.setData({
            titleDisabled:false,
            contentDisabled: false,
            passnumDisabled: false,
            saveBtnDisabled:false,
            display_new:true,
            display_look:false,
            titleBorderOpacity:1,
            titleInputOpacity:1,
            contentBorderOpacity:1,
            contentTextAreaOpacity: 1,
            passnumBorderOpacity: 1,
            passnumTextAreaOpacity: 1,
            btnSaveBorderOpacity:1,
            btnTxt:'保存'
          })
        }
        if(typeof(options.id)=="string"){
          this.setData({
            titleDisabled:false,
            contentDisabled: false,
            passnumDisabled: false,
            display_new:true,
            display_look:true,
            saveBtnDisabled:false,
            titleBorderOpacity:1,
            titleInputOpacity:1,
            contentBorderOpacity:1,
            contentTextAreaOpacity: 1,
            passnumBorderOpacity: 1,
            passnumTextAreaOpacity: 1,
            btnSaveBorderOpacity:1,
            btnTxt:'重新保存',
            deleteDisplay:'block'
          })
        }
        wx.getSystemInfo({
          success: function(res) {
            that.setData({
              tabWidth:res.windowWidth/2,
              contentTextAreaHeight: res.windowHeight * 0.04
            })
          }
        })
        id=options.id;
        var that=this;
        var title=wx.getStorageSync('title');
        var content = wx.getStorageSync('content');
        var passnum = wx.getStorageSync('passnum');
        var titleValue = title[id - 1], contentValue = content[id - 1], passnumValue = content[id - 1];
        this.setData({
            titleValue:titleValue,
            contentValue: contentValue,
            passnumValue: passnumValue
        })
      }

      太长了,这是替换内容

      2018-06-30
      赞同
      回复
    • .
      .
      2018-06-30回复人生若只如初见

      经过远程调试,我发现记录有三个值,但是查询只能看到两个值!!

      2018-06-30
      赞同
      回复
    查看更多(4)