小程序
小游戏
企业微信
微信支付
扫描小程序码分享
这个是首页代码,,
保存后查看,下面的两个值是一样的。。因为这个原来是两个输入框的,我复制了一个输入框的代码,js代码也添加了一份。怎么破,求解啊
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你代码图片 那么小 根本看不清 .....
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
<
view
class
=
"newNotePad"
>
image
style
"width:30px;height:30px; float:left; margin-left:10px; display:{{deleteDisplay}};"
src
"../../pages/images/delete.png"
bindtap
"deleteNotePad"
></
"width:30px;height:30px; margin-right:10px;background-color:green;"
"../../pages/images/new.png"
</
"alert"
"display:{{alertDisplay}}"
>输入框不能为空!</
form
bindsubmit
"noteSubmit"
bindreset
"noteReset"
"title"
"opacity:{{titleBorderOpacity}}"
input
"opacity:{{titleInputOpacity}}"
name
type
"text"
value
"{{titleValue}}"
disabled
"{{titleDisabled}}"
placeholder
"备注"
maxlength
"18"
bindfocus
"titleInputBindfocus"
"content"
"opacity:{{contentBorderOpacity}};"
textarea
"opacity:{{contentTextAreaOpacity}};height:{{contentTextAreaHeight}}px;"
"{{contentValue}}"
"{{contentDisabled}}"
"1"
"contentTextareaBindfocus"
"passnum"
"opacity:{{passnumBorderOpacity}};"
"opacity:{{passnumTextAreaOpacity}}"
"{{passnumValue}}"
"{{passnumDisabled}}"
"passnumTextareaBindfocus"
"btnNote {{display_new?'display':'display_none'}}"
"border:1px solid green;border-radius: 4px; width:96%; margin-left: 2%; opacity:{{btnSaveBorderOpacity}} "
button
"background-color:green;height:40px;line-height:40px; color:white; "
"{{saveBtnDisabled}}"
formType
"submit"
"saveNotePad"
>{{btnTxt}}</
"bottomBar"
"display:flex;"
navigator
url
"../../pages/index/index?state=new"
redirect>
"text-align:center; width:{{tabWidth}}px;"
><
"width:25px; height:25px;"
"../../pages/images/writeSelected.png"
text
"font-size:10pt; color:#006633"
>记录事件</
"../../pages/checkNote/checkNote"
"../../pages/images/search.png"
"font-size:10pt;"
>查看日记</
js 代码 也发一下 这部分 看着 没什么 问题 不过 不太清楚 为什么用focus事件
var
id,state;
Page({
data:{
tabWidth:
''
,
titleDisabled:
true
contentDisabled:
passnumDisabled:
saveBtnDisabled:
inputValue:
contentValue:
passnumValue:
display_new:
display_look:
false
updateBtnDisabled:
resaveBtnDisabled:
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:
},
newNotePad:
function
(e){
wx.redirectTo({
url:
'../../pages/index/index?state=new'
})
deleteNotePad:
(){
wx.showModal({
title:
'删除'
content:
'确认删除这条记录吗?'
success:
(res){
if
(res.confirm){
console.log(
'确定'
)
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)
, content)
, passnum)
, dateNow)
wx.showToast({
'删除成功'
'../../pages/checkNote/checkNote'
// success
fail:
() {
// fail
complete:
// complete
}
catch
console.log(e.message)
else
'取消'
noteSubmit:
(state==
'new'
){
//如果点击了新建
"现在点击的功能是保存"
(e.detail.value.title.length == 0 && e.detail.value.content.length == 0 && e.detail.value.passnum.length == 0){
this
.setData({
'block'
titleBorderOpacity:0.6,
titleInputOpacity:0.6,
contentBorderOpacity:0.6,
contentTextAreaOpacity: 0.6,
passnumBorderOpacity: 0.6,
passnumTextAreaOpacity: 0.6,
btnSaveBorderOpacity:0.6
title=wx.getStorageSync(
) || [];
content = wx.getStorageSync(
passnum = wx.getStorageSync(
date=
new
Date();
year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds();
dateNow=year+
"年"
+month+
"月"
+day+
"日 "
+hour+
"时"
+minute+
"分"
+second+
"秒"
dateNowInfo=wx.getStorageSync(
title.unshift(e.detail.value.title);
content.unshift(e.detail.value.content);
passnum.unshift(e.detail.value.passnum);
dateNowInfo.unshift(dateNow);
, dateNowInfo)
'保存成功'
(
typeof
(id)==
"string"
"现在点击的功能是重新保存"
) || [], content = wx.getStorageSync(
) || [], passnum = wx.getStorageSync(
) || [],dateNowInfo=wx.getStorageSync(
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)
console.log(e.message);
+dateNow[id-1]);
noteReset:
titleInputBindfocus:
titleBorderOpacity:1,
titleInputOpacity:1,
contentBorderOpacity:1,
contentTextAreaOpacity: 1,
passnumBorderOpacity: 1,
passnumTextAreaOpacity: 1,
(第二段替换词)
contentTextareaBindfocus:
passnumTextareaBindfocus:
(id) ==
) {
titleBorderOpacity: 1,
titleInputOpacity: 1,
contentBorderOpacity: 1,
saveNotePad:
//保存按钮
"new"
contentBorderOpacity: 0.4,
onLoad:
(options){
console.log(wx.getStorageSync(
))
"index:"
+options.id);
that=
;
state=options.state
btnSaveBorderOpacity:1,
(options.id)==
'重新保存'
wx.getSystemInfo({
(res) {
that.setData({
tabWidth:res.windowWidth/2,
contentTextAreaHeight: res.windowHeight * 0.04
id=options.id;
titleValue = title[id - 1], contentValue = content[id - 1], passnumValue = content[id - 1];
titleValue:titleValue,
contentValue: contentValue,
passnumValue: passnumValue
太长了,这是替换内容
经过远程调试,我发现记录有三个值,但是查询只能看到两个值!!
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你代码图片 那么小 根本看不清 .....
<
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
>
js 代码 也发一下 这部分 看着 没什么 问题 不过 不太清楚 为什么用focus事件
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,
})
}
},
(第二段替换词)
})
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
})
}
太长了,这是替换内容
经过远程调试,我发现记录有三个值,但是查询只能看到两个值!!