Sometimes some data information on the page is filled in after calculation through js. In the past, developers would often treat the <span>
element as a placeholder and specify an ID attribute so that the JavaScript code could Find it and fill in the data. In
HTML5, it is recommended to use <output>
as a placeholder to make the semantics clearer. The actual usage is the same as the previous <span>
of.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>随机数生成</title> <script> function run(){ var resultElement = document.getElementById("result"); resultElement.value = Math.random(); } </script> </head> <body> <p>随机数:<output id="result"></output></p> <input type="button" value="生成" onclick="run()"> </body> </html>
The above is the detailed content of Example analysis of using output tag to mark JavaScript return value. For more information, please follow other related articles on the PHP Chinese website!