首页题目详情
以下哪条代码可以将一个元素的href属性设置为'index.html'?

A.document.getElementByClassName('link').href = 'index.html';
B.document.querySelector('a').setAttribute('href', 'index.html');
C.document.getElementById('link').setAttribute('href', 'index.html');
D.以上都可以
优质解答
答案
D
解析
如果元素是<a>标签,并且有ID或类名,以上三种方法都可以实现修改href属性。因此,正确答案是D。
Web程序设计单选题中等AI生成