The setAttribute method is a JavaScript method used to set the value of a specific attribute for a given element in an HTML or XML document. It takes two parameters: the name of the attribute and the value to be set.

For example, to set the "src" attribute of an image element with id "myImage" to "image.jpg", the following code can be used:

document.getElementById("myImage").setAttribute("src", "image.jpg");

This will set the "src" attribute of the element with id "myImage" to "image.jpg".

setAttribute

原文地址: http://www.cveoy.top/t/topic/btB8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录