MY 总结:js return true,return false

本文通过一个具体的JavaScript示例展示了return true与return false在实际应用中的区别。通过按钮触发的不同返回值,演示了如何控制页面行为,如阻止默认操作或允许表单提交等。
  1. <script>
  2. functionwindow.onload(){
  3. alert("onload!");
  4. alert("check(1):::returntrue测试::"+check(1));//弹出提示:check(1):::returntrue测试::true
  5. alert("check(0):::returnfalse测试::"+check(0));//弹出提示:check(2):::returnfalse测试::false
  6. }
  7. /*
  8. returnfalse表示返回一个false值,也就是说提交是不成功的。错误之后的js代码不会再运行
  9. returntrue表法返回一个true值,也就是提交了。
  10. */
  11. functioncheck(p)
  12. {
  13. if(p==0)
  14. {
  15. alert("returnfalse测试");
  16. returnfalse;
  17. alert("执行returnfalse以后");//return语句后的语句都不再执行测试带有action时,是否执行action
  18. }
  19. else
  20. {
  21. //return"ispanda";//如果是执行本句,则返回:“ispanda”
  22. alert("returntrue测试");
  23. returntrue;
  24. alert("执行returntrue以后");//return语句后的语句都不再执行
  25. }
  26. alert("if、else中的returnture/false语句没有起作用!");//return语句后的语句都不再执行
  27. }
  28. </script>
  29. <html>
  30. <head>
  31. <TITLE>解决jsreturntrue/false的问题</TITLE>
  32. <inputtype="button"value="测试"onClick="check(0)"/>
  33. </head>
  34. <body>
  35. </body>
  36. </html>
<!DOCTYPE html> <html> <head> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="private, max-age=3"> <meta http-equiv="expires" content="0"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <link rel="stylesheet" href="js/elementui.css"> <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <script type="text/javascript" src="js/vue.min.js"></script> <title></title> <script type="text/javascript" src="js/main0.js"></script> <script type="text/javascript" src="js/jswebrtc.js"></script> <script src="js/flv.min.js"></script> <script src="js/elementui.js"></script> <style type="text/css"> .videolist-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; height: 96vh; background: #f9f9f9; align-items: center; justify-items: center; } .dt-video { border: 1px solid #3E516D; background-color: #060f20; background-repeat: no-repeat; width: 100%; height: 100%; position: relative; } .video_td { z-index: 99999; height: 40px; background-color: #000; position: absolute; bottom: 0; width: 100%; line-height: 40px; font-size: 20px; padding-left: 15px; box-sizing: border-box; color: #fff; } </style> </head> <body style="font-family: '微软雅黑';"> <div class="videolist-grid" id='videolist'> <div v-for='(item, index) in videoList' :id="'video_webrtc' + item.key" class='dt-video'> <div v-if='flag' v-loading="loading" element-loading-text="加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" :id="'bf' + item.key" style='position: absolute; background: url(/clyxjg/bd-image/1.png) bottom/contain, url(/clyxjg/bd-image/2.png) 50%/auto 30%; background-repeat: no-repeat; background-color: #060f20; width: 100%; height: 100%; z-index: 99'> <!-- <span v-on:click='btnvideo(item, index)' style='position: absolute; top: 45%; left: 52%; transform: translate(-50%, -50%); display: inline-block; height: 60px; width: 50px; z-index: 99'> <image v-if='item.flag' style='width:100%;height:100%' src="/video/img/ztbf.png"></image> </span> --> </div> <video v-else class="my-video" muted controls autoplay :id='"viedo" + item.key' silent-play=true style='width: 100%; height: 86%; object-fit: fill'> </video> <div class='video_td'> {{plateNo}} </div> </div> </div> <script type="text/javascript"> $(function () { var vm = new Vue({ el: '#videolist', data: { loading: false, videoList: [ { key: "1", name: "通道 1", flag: true, showtab: false, showLi: true, jz: false, jzsb: false, showvideo: false }, { key: "2", name: "通道 2", flag: true, showtab: false, showLi: true, jz: false, jzsb: false, showvideo: false }, { key: "3", name: "通道 3", flag: true, showtab: false, showLi: true, jz: false, jzsb: false, showvideo: false }, { key: "4", name: "通道 4", flag: true, showtab: false, showLi: true, jz: false, jzsb: false, showvideo: false }, ],//通道 plateNo: "", //车牌号 objCar: {}, //车辆信息 channel: [], //通道号 YPList: [], //视频心跳 shouldContinue:true, flag:true, }, created() { let geturl = window.location.href let getqyinfo = geturl.split('?')[1] let getqys = new URLSearchParams('?' + getqyinfo) //将参数放在 URLSearchParams 函数中 this.plateNo = getqys.get('plateNo') this.videoAddress() this.vehicleDevice() //this.ksbf() */ }, methods: { //获取的视频流地址 videoAddress() { var my = this vsportal("VideoAction.videoAddress", {}).then(function (res) { my.url = res.data.VideoHlsAddr }) }, //获取车辆信息 vehicleDevice() { var my = this vsportal("DcJkAction.VehicleDevice", { cph: my.plateNo }).then(function (res) { my.objCar = res.data //拿到通道号 const num = parseInt(my.objCar.videoChannelNum); my.channel = Array.from({ length: num }, (_, i) => i + 1) my.rTVideoInstruct() }) }, //下发实时音视频传输指令 rTVideoInstruct(simNo, channel) { var my = this my.loading = true for (var i = 0; i < my.channel.length; i++) { vsportal("VideoAction.rTVideoInstruct", { simNo: my.objCar.simNo, channel: my.channel[i] }).then(function (res) { //console.log(res) }) if (i == my.channel.length - 1) { //调用结束,开始获取实时视频心跳 console.log('调用结束') my.rTVideo() setTimeout(() => { my.shouldContinue = false; }, 10000); } } }, //获取实时视频 rTVideo() { var my = this; if (!my.shouldContinue) { return; } vsportal("VideoAction.rTVideo", { simNo: my.objCar.simNo, channels: my.channel.join(',') }).then(function (res) { if (res.status == true) { if (res.data.length == 0) { setTimeout(function () { my.rTVideo(); }, 1000) } else { const allTlztTrue = res.data.every(item => item.value === true); if (allTlztTrue) { //实时心跳获取为 true 的操作 console.log('22') my.YPList = res.data my.loading = false my.flag = false for (var i = 0; i < my.YPList.length; i++) { my.playUrl(i) } } else { setTimeout(function () { my.rTVideo(); }, 1000) } } } }) }, playUrl(i) { const flvUrl = this.url + this.YPList[i].key; const videoElement = document.getElementById('viedo' + this.YPList[i].key); console.log(videoElement) if (flvjs.isSupported()) { const flvPlayer = flvjs.createPlayer({ type: 'flv', url: flvUrl }); flvPlayer.attachMediaElement(videoElement); flvPlayer.load(); flvPlayer.play(); } } } }) }) </script> <style> .none { visibility: hidden; } .my-video::-webkit-media-controls { width: 100px; height: 100px; } .my-video::-webkit-media-controls-enclosure { width: 100%; height: 100%; font-size: 50px; } .my-video::-webkit-media-controls-panel { width: 100%; height: 100%; font-size: 50px; } </style> </body> </html> 拿到的视频播放器videoElement为null,如何修改
最新发布
12-03
<!DOCTYPE html> <html> <head> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="private, max-age=3"> <meta http-equiv="expires" content="0"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <link rel="stylesheet" href="js/elementui.css"> <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <script type="text/javascript" src="js/vue.min.js"></script> <title></title> <script type="text/javascript" src="js/main0.js"></script> <script type="text/javascript" src="js/jswebrtc.js"></script> <script src="js/flv.min.js"></script> <script src="js/elementui.js"></script> <style type="text/css"> .videolist-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; height: 96vh; background: #f9f9f9; align-items: center; justify-items: center; } .dt-video { border: 1px solid #3E516D; background-color: #060f20; background-repeat: no-repeat; width: 100%; height: 100%; position: relative; } .video_td{ z-index: 99999; height: 40px; background-color: #000; position: absolute; bottom: 0; width: 100%; line-height: 40px; font-size: 20px; padding-left: 15px; box-sizing: border-box; color:#fff; } </style> </head> <body style="font-family: '微软雅黑';"> <div class="videolist-grid" id='videolist'> <div v-for='(item,index) in videoList' :id="'video_webrtc' + item.key" class='dt-video'> <div v-loading="loading" element-loading-text="加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" :id="'bf' + item.key" style='position: absolute; background: url(/clyxjg/bd-image/1.png) bottom/contain, url(/clyxjg/bd-image/2.png) 50%/auto 30%; background-repeat: no-repeat; background-color: #060f20; width: 100%; height: 100%; z-index: 99'> <span v-on:click='btnvideo(item,index)' style='position: absolute; top: 45%; left: 52%; transform: translate(-50%, -50%); display: inline-block; height: 60px; width: 50px; z-index: 99'> <image v-if='item.flag' style='width:100%;height:100%' src="/video/img/ztbf.png"></image> </span> </div> <video class="my-video none" muted controls autoplay :id='"viedo" + item.key' silent-play=true style='width: 100%; height: 86%; object-fit: fill'> </video> <div class='video_td'> {{plateNo}} </div> </div> </div> <script type="text/javascript"> $(function () { var vm = new Vue({ el : '#videolist', data :{ loading:false, videoList:[ {key:"1",name:"通道1",flag:true,showtab:false,showLi:true,jz:false,jzsb:false,showvideo:false}, {key:"2",name:"通道2",flag:true,showtab:false,showLi:true,jz:false,jzsb:false,showvideo:false}, {key:"3",name:"通道3",flag:true,showtab:false,showLi:true,jz:false,jzsb:false,showvideo:false}, {key:"4",name:"通道4",flag:true,showtab:false,showLi:true,jz:false,jzsb:false,showvideo:false}, ],//通道 plateNo:"", //车牌号 objCar:{}, //车辆信息 channel:[], //通道号 YPList:[], //视频心跳 }, created(){ let geturl = window.location.href let getqyinfo = geturl.split('?')[1] let getqys = new URLSearchParams('?'+getqyinfo) //将参数放在URLSearchParams函数中 this.plateNo = getqys.get('plateNo') this.videoAddress() this.vehicleDevice() //this.ksbf() */ }, methods:{ //获取的视频流地址 videoAddress(){ var my = this vsportal("VideoAction.videoAddress",{}).then(function(res){ my.url = res.data.VideoHlsAddr }) }, //获取车辆信息 vehicleDevice(){ var my = this vsportal("DcJkAction.VehicleDevice",{cph:my.plateNo}).then(function(res){ my.objCar = res.data //拿到通道号 const num = parseInt(my.objCar.videoChannelNum); my.channel = Array.from({ length: num }, (_, i) => i + 1) my.rTVideoInstruct() }) }, //下发实时音视频传输指令 rTVideoInstruct(simNo,channel){ var my = this for(var i=0; i<my.channel.length; i++){ vsportal("VideoAction.rTVideoInstruct",{simNo:my.objCar.simNo,channel:my.channel[i]}).then(function(res){ //console.log(res) }) if(i==my.channel.length-1){ //调用结束,开始获取实时视频心跳 console.log('调用结束') my.rTVideo() } } }, //获取实时视频 rTVideo(){ var my=this; vsportal("VideoAction.rTVideo",{simNo:my.objCar.simNo,channels:my.channel.join(',')}).then(function(res){ if(res.status == true){ if(res.data.length ==0){ setTimeout( function(){ my.rTVideo(); },1000 ) }else{ const allTlztTrue = res.data.every(item => item.value === true); if (allTlztTrue) { //实时心跳获取为true的操作 console.log('22') my.YPList = res.data for(var i=0; i<my.YPList.length; i++){ my.playUrl(i) } } else { setTimeout( function(){ my.rTVideo(); },1000 ) } } } }) }, playUrl(i){ var flvUrl = this.url + this.YPList[i].key; console.log(flvUrl) var video = document.getElementById('video_webrtc'+this.channel[i]).querySelector('video'); var option={ video: video, autoplay: true, muted:true, } var player = new JSWebrtc.Player(flvUrl,option); }, } }) }) </script> <style> .none { visibility: hidden; } .my-video::-webkit-media-controls { width: 100px; height: 100px; } .my-video::-webkit-media-controls-enclosure { width: 100%; height: 100%; font-size: 50px; } .my-video::-webkit-media-controls-panel { width: 100%; height: 100%; font-size: 50px; } </style> </body> </html>实时视频调用的时候,一分钟后停止调用
12-03
'test+++', '6666', { options: { uri: 'mqtt://broker.hivemq.com:1883', clientId: 'my-client-id', username: 'your-username', password: 'your-password', protocol: 'ws', defaultProtocol: 'ws', keepalive: 60, reschedulePings: true, protocolId: 'MQTT', protocolVersion: 4, reconnectPeriod: 1000, connectTimeout: 30000, clean: true, resubscribe: true, customHandleAcks: [Function], hostname: 'localhost', port: 80, path: '/', wsOptions: { objectMode: false } }, streamBuilder: [Function: wrapper], outgoingStore: { options: { clean: true }, _inflights: {} }, incomingStore: { options: { clean: true }, _inflights: {} }, queueQoSZero: true, _resubscribeTopics: {}, messageIdToTopic: {}, pingTimer: null, connected: false, disconnecting: false, queue: [], connackTimer: 9913, reconnectTimer: null, _storeProcessing: false, _packetIdsDuringStoreProcessing: {}, nextId: 28955, outgoing: {}, _firstConnection: true, _events: { close: [ [Function], [Function], [Function] ], connect: [Function] }, _eventsCount: 2, _maxListeners: undefined, stream: { _readableState: { objectMode: false, highWaterMark: 16384, buffer: { head: null, tail: null, length: 0 }, length: 0, pipes: { _writableState: { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: false, errorEmitted: false, bufferedRequestCount: 0, corkedRequestsFree: { next: null, entry: null, finish: [Function] } }, writable: true, _write: [Function], _callbacks: { unpipe: [ [Function: onunpipe] ], drain: [ [Function] ], error: [ [Function: onerror] ], close: [ { [Function: on] fn: [Function: onclose] } ], finish: [ { [Function: on] fn: [Function: onfinish] } ] } }, pipesCount: 1, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, destroyed: false, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, _writableState: { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 56, writing: true, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: [Function: nop], writelen: 1, bufferedRequest: { chunk: { '0': 54 }, encoding: 'buffer', isBuf: true, callback: [Function: nop], next: { chunk: { '0': 0, '1': 4 }, encoding: 'buffer', isBuf: true, callback: [Function: nop], next: { chunk: { '0': 77, '1': 81, '2': 84, '3': 84 }, encoding: 'buffer', isBuf: true,这次里面有没有connect方法?
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值