ESP32-Web-Server编程- JS 基础 3
概述
本示例演示通过 button 控件的 onclick 内联属性,实现在网页上点击按钮,切换 LED 灯图标的转变。
示例解析
前端设计
前端代码建立了一个 id 为 “imageLamp” 的图片对象。并建立两个按钮,设计两个按钮的 onclick 事件为引用不同的图片。
<p>
<img id="imageLamp" src="light_on.png">
</p>
<p>
<button onclick="document.getElementById('imageLamp').src='light_on.png'">Turn on the light</button>
</p>
<p>
<button onclick="document.getElementById('imageLamp').src='light_off.png'">Turn off the light</button>
</p>