微信小程序:在提交函数中加个判断,比较上车下车变量相同返回,并弹窗提醒:上车下车信息不能相同。为空也返回并提醒:上车下车信息不能为空
时间: 2024-03-22 16:40:56 浏览: 19
好的,我理解你的意思了。你可以在提交函数中添加如下的判断逻辑:
```
function submit() {
var getOn = document.getElementById("getOn").value;
var getOff = document.getElementById("getOff").value;
if (getOn === getOff) {
alert("上车下车信息不能相同");
return;
}
if (!getOn || !getOff) {
alert("上车下车信息不能为空");
return;
}
// 在这里添加你的提交逻辑
}
```
这段代码的作用是先获取上车和下车的值,然后进行两个判断:
1. 如果上车和下车的值相同,则弹窗提醒“上车下车信息不能相同”,并退出函数。
2. 如果上车或下车的值为空,则弹窗提醒“上车下车信息不能为空”,并退出函数。
如果两个判断都不满足,则说明输入的信息符合要求,可以继续执行提交逻辑。
相关问题
微信小程序,在提交函数中加个判断,比较上车下车变量相同返回,为空也返回
好的,你的问题是如何在微信小程序的提交函数中加入判断,比较上车下车变量相同就返回,为空也返回。针对这个问题,我可以给出以下的代码示例:
```javascript
function submit(start, end) {
if (start === end || !start || !end) {
return; // 上车下车点相同或为空,直接返回
}
// 其他代码逻辑
// ...
}
```
在这个代码示例中,我们首先判断上车点和下车点是否相同,如果相同直接返回。接着,我们又对上车点和下车点进行了非空判断,如果其中任意一个为空,也直接返回。这样做可以有效地防止程序出现异常情况。当然,具体的判断条件可以根据实际需求进行调整。
需要注意的是,在微信小程序中,提交函数可能是由用户触发的某个事件调用的,因此我们需要根据具体的场景进行相应的修改。
在下面代码中加入微信小程序:在提交函数中加个判断,比较上车下车变量相同返回,为空也返回的内容。request(){ // 获取登录状态 var isLogin = wx.getStorageSync('isLogin'); if (isLogin) { const that = this wx.navigateTo({ url: '../Viewing/Viewing?boardingPoint='+that.data.tihuoWay+'&dropoffPoint='+that.data.tihuoWayTwo, success(res){ console.log(res) },fail(err){ console.error(err) } }) } else{ // 未登录,弹出提示框并跳转到登录页面 wx.showToast({ title: '您还没有登录', icon: 'error', duration: 2000 }) setTimeout(function() { wx.switchTab({ url: '../loginin/loginin' }) }, 2000); } },
可以按照以下方式在提交函数中加入微信小程序的判断:
```
request(){
// 获取登录状态
var isLogin = wx.getStorageSync('isLogin');
if (isLogin) {
const that = this
// 判断上车下车变量是否相同
if (that.data.tihuoWay === that.data.tihuoWayTwo) {
wx.showToast({
title: '上车下车不能相同',
icon: 'error',
duration: 2000
})
return
}
// 判断上车下车变量是否为空
if (!that.data.tihuoWay || !that.data.tihuoWayTwo) {
wx.showToast({
title: '上车下车不能为空',
icon: 'error',
duration: 2000
})
return
}
wx.navigateTo({
url: '../Viewing/Viewing?boardingPoint='+that.data.tihuoWay+'&dropoffPoint='+that.data.tihuoWayTwo,
success(res){
console.log(res)
},
fail(err){
console.error(err)
}
})
} else{
// 未登录,弹出提示框并跳转到登录页面
wx.showToast({
title: '您还没有登录',
icon: 'error',
duration: 2000
})
setTimeout(function() {
wx.switchTab({
url: '../loginin/loginin'
})
}, 2000);
}
},
```
在这段代码中,我们首先判断了上车下车变量是否相同以及是否为空。如果有任何一个条件不满足,就会弹出提示框并返回。如果条件都满足,就会跳转到指定的页面。
需要注意的是,这里的判断条件只是一个示例,具体根据你的实际需求进行修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)