解决this.disabled=true,不能执行服务器端代码的问题

ASP.NET按钮点击事件
本文介绍了一个ASP.NET页面中的按钮点击事件处理方式。通过一个示例展示了如何使用Button控件,并在点击时隐藏该按钮同时显示另一个提示按钮。这种方法常用于表单提交过程中显示加载状态。
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="this.style.display='none';btnokHide.style.display='block';" />
    <input id="btnokHide"  type="button" value="正在提交..." style="display:none;" disabled="disabled" />
//表单初始化 function initForm(){ var d; fm.CurrentDate.value = "<%=CurrentDate%>"; fm.CurrentTime.value = "<%=CurrentTime%>"; d = new Date(); //简易投保没有告知 if (BussSubType == "08"){ fm.pagename.value = "1108";} //意外险投保单投保人没有告知,被保人 if (BussSubType =="06"){ fm.pagename.value = "1106";} //经代寿险投保书 if (BussSubType == "09"){ fm.pagename.value ="1109";} //经代万能投保书 if (BussSubType == "10"){ fm.pagename.value = "1110";} //经代寿险投保书 if (BussSubType == "31"){ fm.pagename.value = "1131";} //经代万能投保书 if (BussSubType == "33"){ fm.pagename.value = "1133";} //个险经代投保书(新版) if (BussSubType =="04"){ fm.pagename.value = "1104"; } //个险经代意外投保书(新版) if (BussSubType == "11"){ fm.pagename.value = "1111";} //个险寿险投保书(新版) if (BussSubType =="41"){ fm.pagename.value = "11";} //个险意外投保书(新版) if (BussSubType =="43"){ fm.pagename. value = "1143"; } //个险VIP投保书(新版) if (BussSubType == "42"){ fm.pagename.value ="1142";} //个险逍遥贷专用 if (BussSubType == "48"){ fm.pagename.value = "1148";} //Q:scantype是判断是否有扫描件,用于定制随动 if(scantype=="scan"){ setFocus();} else{ fm.appntdiseaseimpart.disabled=true ; fm.appnthealimpart.disabled=true ; fm.insufinaimpart.disabled=true ; fm.insuhealimpart.disabled=true ; fm.insudiseaseimpart.disabled = true;} //初始化业务员告知 initAgentImpartGrid() ; //初始化投保人告知信息 initImpartGrid() ; //初始化工作流任务节点 initMissionID() ; //初始化多业务员列表 initMultiAgentGrid() ; //判断是否是有扫描件 /* *ScanFlag=0--有扫描 *ScanFlaa=1--下扫描*/ if(this.ScanFlag == "1"){ if(fm. SaleChnl.value=="10"){ if(BussSubType=="58"||BussSubType=="59"||BussSubType=="64"||BusssubType=="65"||BussSubType=="60"||BussSubType=="61"||BussSubType=="62"|| BussSubType=="63"||BussSubType=="78") { frtype.style.display=""; }else{ if(fm. SaleChnl.value=="10"){ frtype.style.display="" ; }} if(this.ScanFlag == "0"){ //根据需求PrtNo中存投保单号,故将投保单号字段赋值 fm.all('PrtNo').value = prtNo; fm.all('PrtNo2').value = prtNo; fm.all('ProposalContNo').value = prtNo; fm.a11('ContNo').value = prtNo; fm.all('ManageCom').value = ManageCom; fm.all('ActivityID').value = ActivityID; fm.al1('NoType').value = NoType; fm.PrtNo.readOnly=true; if(this.ScanFlag =="1"){ fm.all('PrtNo').value = prtNo; fm.all('PrtNo2').value = prtNo; fm.all('ProposalContNo').value = prtNo; fm.all('ContNo').value = prtNo; fm.all('ManageCom').value = ManageCom; fm.all('ActivityID').value = ActivityID; fm.all ('NoType').value = NoType; fm.PrtNo.readOnly=true;} //初始化”是否选择电子保单“ //判断是否是银保通非实时单 checkYBT(); 给上述代码添加详细的注释,并解释相关方法
03-14
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>WebRTC视频流客户端</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 100%; margin: 0 auto; padding: 20px; background-color: #f5f5f5; } h1 { color: #2c3e50; text-align: center; margin-bottom: 30px; } #videoContainer { position: relative; width: 1200px; height: 600px; margin: 0 auto; background-color: #000; border-radius: 4px; overflow: hidden; } #video { width: 100%; height: 100%; object-fit: cover; background-color: #000; } #videoError { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px; background-color: rgba(0, 0, 0, 0.7); z-index: 10; } #controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 20px; } button { padding: 10px 25px; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; transition: all 0.3s; } #startButton { background-color: #3498db; color: white; } #stopButton { background-color: #e74c3c; color: white; } button:disabled { opacity: 0.6; cursor: not-allowed; background-color: #95a5a6 !important; } #status { padding: 15px; text-align: center; border-radius: 4px; margin-bottom: 20px; font-weight: bold; color: white; } .status-waiting { background-color: #7f8c8d; } .status-connecting { background-color: #f39c12; } .status-connected { background-color: #2ecc71; } .status-error { background-color: #e74c3c; } #debugPanel { background-color: white; border-radius: 4px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); } .debug-section { margin-bottom: 15px; } .debug-section h3 { margin-top: 0; color: #2c3e50; border-bottom: 1px solid #eee; padding-bottom: 5px; } .debug-row { display: flex; margin-bottom: 8px; } .debug-label { width: 120px; font-weight: bold; } .debug-value { flex-grow: 1; font-family: monospace; } #videoStats { background-color: #f8f9fa; padding: 10px; border-radius: 4px; } </style> </head> <body> <h1>WebRTC视频流客户端</h1> <div id="videoContainer"> <video id="video" autoplay playsinline ></video> <div id="videoError">等待连接...</div> </div> <div id="controls"> <button id="startButton">开始连接</button> <button id="stopButton" disabled>停止连接</button> </div> <div id="status" class="status-waiting">状态: 等待连接</div> <div id="debugPanel"> <div class="debug-section"> <h3>连接状态</h3> <div class="debug-row"> <span class="debug-label">ICE状态:</span> <span id="iceState" class="debug-value">-</span> </div> <div class="debug-row"> <span class="debug-label">信令状态:</span> <span id="signalingState" class="debug-value">-</span> </div> <div class="debug-row"> <span class="debug-label">连接状态:</span> <span id="connectionState" class="debug-value">-</span> </div> </div> <div class="debug-section"> <h3>视频信息</h3> <div id="videoStats"> <div class="debug-row"> <span class="debug-label">轨道状态:</span> <span id="trackState" class="debug-value">-</span> </div> <div class="debug-row"> <span class="debug-label">分辨率:</span> <span id="videoResolution" class="debug-value">-</span> </div> <div class="debug-row"> <span class="debug-label">帧率:</span> <span id="videoFramerate" class="debug-value">-</span> </div> <div class="debug-row"> <span class="debug-label">最后错误:</span> <span id="lastError" class="debug-value">无</span> </div> </div> </div> </div> <script> class WebRTCClient { constructor() { // DOM元素 this.videoElement = document.getElementById('video'); this.videoError = document.getElementById('videoError'); this.startButton = document.getElementById('startButton'); this.stopButton = document.getElementById('stopButton'); this.statusDiv = document.getElementById('status'); // 调试信息元素 this.iceStateEl = document.getElementById('iceState'); this.signalingStateEl = document.getElementById('signalingState'); this.connectionStateEl = document.getElementById('connectionState'); this.trackStateEl = document.getElementById('trackState'); this.videoResolutionEl = document.getElementById('videoResolution'); this.videoFramerateEl = document.getElementById('videoFramerate'); this.lastErrorEl = document.getElementById('lastError'); // 状态变量 this.pc = null; this.statsInterval = null; this.frameCount = 0; this.lastFrameTime = 0; this.lastVideoWidth = 0; this.lastVideoHeight = 0; // 初始化 this.initEventListeners(); } initEventListeners() { // 监听开始连接按钮 连接 this.startButton.addEventListener('click', () => this.connect()); // 监听停止连接按钮 断开连接 this.stopButton.addEventListener('click', () => this.disconnect()); this.videoElement.addEventListener('loadedmetadata', () => { this.updateVideoStats(); }); this.videoElement.addEventListener('error', () => { this.showError('视频元素发生错误'); }); } async connect() { try { this.prepareForConnection(); // 创建PeerConnection this.pc = new RTCPeerConnection( { iceServers: [ { urls: "stun:stun.l.google.com:19302" }, { urls: "stun:stun1.l.google.com:19302" } ] } ); // 设置事件监听 this.setupConnectionEvents(); // 创建并发送Offer const offer = await this.pc.createOffer({ offerToReceiveVideo: true, offerToReceiveAudio: false }); await this.pc.setLocalDescription(offer); // 发送Offer到服务器 const response = await this.sendOfferToServer(offer); // 处理服务器返回的Answer await this.pc.setRemoteDescription( new RTCSessionDescription(response) ); // 开始收集统计信息 this.startStatsCollection(); } catch (err) { this.handleConnectionError(err); } } async sendOfferToServer(offer) { const response = await fetch('http://10.10.23.157:8080/offer', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sdp: offer.sdp, type: offer.type }) }); if (!response.ok) { throw new Error(`服务器错误: ${response.status}`); } return await response.json(); } prepareForConnection() { this.videoError.style.display = 'none'; this.startButton.disabled = true; this.stopButton.disabled = false; this.updateStatus('正在连接...', 'connecting'); if (this.pc) { this.pc.close(); } } setupConnectionEvents() { this.pc.oniceconnectionstatechange = () => { const state = this.pc.iceConnectionState; this.iceStateEl.textContent = state; if (state === 'connected') { this.updateStatus('连接成功', 'connected'); } else if (state === 'failed') { this.showError('ICE连接失败'); } }; this.pc.onsignalingstatechange = () => { this.signalingStateEl.textContent = this.pc.signalingState; }; this.pc.onconnectionstatechange = () => { const state = this.pc.connectionState; this.connectionStateEl.textContent = state; if (state === 'connected') { this.updateStatus('连接成功', 'connected'); } else if (state === 'disconnected' || state === 'failed') { this.showError('连接断开'); } }; this.pc.ontrack = (event) => { if (event.track.kind === 'video') { this.handleVideoTrack(event); } }; } handleVideoTrack(event) { console.log('收到视频轨道:', event.track); this.trackStateEl.textContent = '活跃'; const stream = new MediaStream(); stream.addTrack(event.track); this.videoElement.srcObject = stream; // 检测视频是否有效 const checkVideoValid = () => { if (this.isVideoBlank()) { this.showError('视频流异常'); } else { this.videoError.style.display = 'none'; this.updateVideoStats(); } if (this.pc && this.pc.connectionState !== 'closed') { setTimeout(checkVideoValid, 1000); } }; checkVideoValid(); } isVideoBlank() { // 简单检测视频是否空白 return this.videoElement.readyState === 0 || (this.videoElement.videoWidth === 0 && this.videoElement.videoHeight === 0); } startStatsCollection() { if (this.statsInterval) clearInterval(this.statsInterval); this.statsInterval = setInterval(async () => { if (!this.pc) return; try { const stats = await this.pc.getStats(); let frameStats = null; stats.forEach(report => { if (report.type === 'inbound-rtp' && report.kind === 'video') { frameStats = report; } }); if (frameStats) { const fps = frameStats.framesPerSecond || 0; this.videoFramerateEl.textContent = `${fps} fps`; } this.updateVideoStats(); } catch (err) { console.error('获取统计信息失败:', err); } }, 1000); } updateVideoStats() { // 更新分辨率 if (this.videoElement.videoWidth > 0 && this.videoElement.videoHeight > 0) { this.videoResolutionEl.textContent = `${this.videoElement.videoWidth}×${this.videoElement.videoHeight}`; } } showError(message) { this.videoError.textContent = message; this.videoError.style.display = 'flex'; this.lastErrorEl.textContent = message; this.updateStatus(message, 'error'); } updateStatus(message, status) { this.statusDiv.textContent = `状态: ${message}`; this.statusDiv.className = `status-${status}`; } handleConnectionError(err) { console.error('连接错误:', err); this.showError(err.message); this.disconnect(); } disconnect() { if (this.pc) { this.pc.close(); this.pc = null; } if (this.statsInterval) { clearInterval(this.statsInterval); this.statsInterval = null; } this.videoElement.srcObject = null; this.startButton.disabled = false; this.stopButton.disabled = true; this.updateStatus('已断开连接', 'waiting'); this.videoError.style.display = 'flex'; this.videoError.textContent = '已断开连接'; // 重置调试信息 this.iceStateEl.textContent = '-'; this.signalingStateEl.textContent = '-'; this.connectionStateEl.textContent = '-'; this.trackStateEl.textContent = '-'; this.videoResolutionEl.textContent = '-'; this.videoFramerateEl.textContent = '-'; } } // 初始化客户端 document.addEventListener('DOMContentLoaded', () => { window.client = new WebRTCClient(); }); </script> </body> </html> <!--const pc = new RTCPeerConnection();--> <!--pc.onaddstream = e => videoElement.srcObject = e.stream;--> <!--const offer = await pc.createOffer();--> <!--await pc.setLocalDescription(offer);--> <!--// 发送offer到服务器的/offer端点--> <!--const response = await fetch('/offer', {--> <!--method: 'POST',--> <!--body: JSON.stringify(pc.localDescription)--> <!--});--> <!--const answer = await response.json();--> <!--await pc.setRemoteDescription(answer);-->以上代码显示视频流异常出现卡顿的原因
08-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值