gpt4 book ai didi

javascript - Tizen Javascript 函数未定义 : Uncaught ReferenceError: checkToggle is not defined

转载 作者:行者123 更新时间:2023-11-28 06:35:35 28 4
gpt4 key购买 nike

我正在尝试在 gear s2 的 tizen Web 应用程序中向我的服务器发出简单的 http 请求。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<title>Wearable UI</title>
<link rel="stylesheet" href="../../lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" href="../../css/style.css">
<!--<script type="text/javascript" src="toggle.js"></script>-->
<script type="text/javascript" >
function checkToggle(name){
//make box2 = box1 when checked
var checkbox = document.getElementById(name);
if (checkbox.checked == 1){
HTTPReq('http://secret.nl/WebServer/edit.php?name='+name+'&value=1');
console.log("set "+name+" ON");
}else{
HTTPReq('http://secret.nl/WebServer/edit.php?name='+name+'&value=0');
console.log("set "+name+" OFF");
}
}
function HTTPReq(theUrl){
console.log('httpReq');
var client = new XMLHttpRequest();
client.open('GET', theUrl);
client.send();
}
</script>
</head>
<body>
<div class="ui-page" data-enable-page-scroll="false">
<div class="ui-content">
<div class="ui-switch">
<div class="ui-switch-text">
Led001
</div>
<div class="ui-toggleswitch ui-toggleswitch-large">
<input type="checkbox" class="ui-switch-input" id="Led001" onclick="checkToggle('Led001')">
<div class="ui-switch-button"></div>
</div>
<div class="ui-switch-sub-text">
Bedroom Light
</div>
</div>
</div>
<script src="controls.js"></script>
</div>
</body>
<script type="text/javascript" src="../../lib/tau/wearable/js/tau.min.js"></script>

</html>

当我模拟这个时,我收到错误:Uncaught ReferenceError:checkToggle 未定义。然而,当我处于网络模拟器模式和实时编辑时保存相同的文件时。该代码有效....?谁能解释一下并告诉我如何解决这个问题。谢谢

最佳答案

尝试:

document.getElementById("Led001").addEventListener("click", function(){
checkToggle("Led001")
})

并从 HTML 中删除onClick

关于javascript - Tizen Javascript 函数未定义 : Uncaught ReferenceError: checkToggle is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34316324/

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