<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>ESP8266 LED Control</title> <style type="text/css"> .slider { -webkit-appearance: none; width: 50%; height: 20px; background: #ddd; outline: none; opacity: 0.7; -webkit-transition: opacity .2s; transition: opacity .2s; } .slider:hover { opacity: 1; } .slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: #4CAF50; cursor: pointer; } .slider::-moz-range-thumb { width: 20px; height: 20px; background: #4CAF50; cursor: pointer; } </style></head><body> <h1>ESP8266 LED Control</h1> <input type="range" min="0" max="255" value="0" class="slider" id="brightnessSlider"> <p>Brightness: <span id="brightnessValue">0</span></p> <script> var slider = document.getElementById("brightnessSlider"); var output = document.getElementById("brightnessValue"); output.innerHTML = slider.value; slider.oninput = function() { output.innerHTML = this.value; sendBrightness(this.value); } function sendBrightness(value) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log("Brightness set to: " + value); } }; xhttp.open("GET", "/brightness?value=" + value, true); xhttp.send(); } </script></body></html>这是你写给我的代码,为什么brightness后的值一直是0,而不会随滑条的值改变
时间: 2024-03-19 17:40:03 浏览: 293
这可能是因为您没有正确设置服务器端的代码来处理ESP8266发送的HTTP GET请求。服务器端代码应该解析“value”参数,并将其用于更改LED亮度。您可以检查服务器端代码是否正确处理了此请求。如果服务器端代码正确,您还可以在ESP8266端使用串行监视器来检查是否正确发送了HTTP GET请求。
阅读全文