gpt4 book ai didi

Javascript 在错误后继续运行代码

转载 作者:行者123 更新时间:2023-12-03 00:43:51 25 4
gpt4 key购买 nike

我正在对一些值进行测试,看看哪个值给出了正确的输出。

每次更改代码时都需要重新部署到服务器,这会影响服务器上的并发用户。

我想尽量减少这种情况。

即使发现错误,是否可以继续运行代码?

Javascript:

var schedule = document.getElementById("<%=ddlExecutionSchedule.ClientID%>").value;
console.log("schedule is " + schedule); //returns UNDEFINED

var schedule2 = document.getElementById("<%=ddlExecutionSchedule.ClientID%>").length;
console.log("schedule2 is " + schedule2); //returns UNDEFINED

var schedule3 = document.getElementById('ddlExecutionSchedule');
console.log("schedule3 is " + schedule3); //returns HTML OBJECT

var schedule4 = document.getElementById('ddlExecutionSchedule').value;
console.log("schedule4 is " + schedule4); //returns UNDEFINED

var schedule5 = document.getElementById('ddlExecutionSchedule').length;
console.log("schedule5 is " + schedule5); //returns UNDEFINED

var schedule6 = document.getElementById(<%=ddlExecutionSchedule.ClientID%>);
console.log("schedule6 is " + schedule6); //returns NULL

var options = schedule.getElementsByTagName('input');
//^ = The line above caught an error of <Uncaught TypeError:
Cannot read property 'getElementsByTagName' of undefined

var options2 = schedule2.getElementsByTagName('input');
//^ = To test

...

感谢您的帮助。

最佳答案

trycatch 会有所帮助:

var schedule1 = document.getElementById("id1").length;
console.log("schedule1 is " + schedule1); //returns UNDEFINED

var schedule2 = document.getElementById("id1");
console.log("schedule2 is " + schedule2);

try {
var options1 = schedule1.getElementsByTagName('input');
console.log('options1: ' + options1);
} catch (err) {
console.log('error: '+ err.message);
}
var options2 = schedule2.getElementsByTagName('input');
console.log('options2: ' + options2);
<label id="id1"><input></label>

关于Javascript 在错误后继续运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53330211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com