运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <select> <option label="Volvo">Volvo (Latin for "I roll")</option> <option id="myOption" label="Mercedes">Mercedes (Mercedes-Benz)</option> </select> <p>Click the button to change the value of the label attribute of the Mercedes option.</p> <p><strong>Note:</strong> It is not possible to set the label property in Firefox (only return).</p> <p><b>Tip:</b> Open the drop-down list before and after you have clicked the button.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myOption").label = "newLabel"; document.getElementById("demo").innerHTML = "The value of the label attribute was changed from 'Mercedes' to 'newLabel'."; } </script> </body> </html>