我正在使用Bootstrap手风琴,它具有以下代码:

 <div class="panel-heading" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">


我想动态创建手风琴,但是我无法在JavaScript中将.href值设置为div。

var accordionHead = document.createElement("div");
accordionHead.className = "panel-heading";
accordionHead.dataset.parent = "#accordion";
accordionHead.dataset.toggle = "collapse";
accordionHead.href = "#id_"+player.pos;


其他所有选项都会得到重视,而.href不会,因此手风琴无法正常工作。还有其他选项可以将.href值赋予div吗?

最佳答案

var accordionHead = document.createElement("div");
accordionHead.className = "panel-heading";
accordionHead.dataset.parent = "#accordion";
accordionHead.dataset.toggle = "collapse";
accordionHead.setAttribute("href","#id_"+player.pos);`

10-07 22:20