[英]Can't get Bootstrap close button to show
I have a close (x) button in bootstrap that I can't get to show using javascript. 我在引导程序中有一个关闭(x)按钮,无法使用javascript显示。 As soon as I give it the class name
close
it disappears. 我给它的类名
close
它便消失了。 What gives? 是什么赋予了?
var btn = document.createElement("button"); //<button> element
btn.className("close"); <!-- unless commented out it won't show -->
var t = document.createTextNode("x"); <!-- would rather use × but this will work for now -->
btn.setAttribute("class", "close"); <!-- tried this and didn't work either -->
cell4.appendChild(btn);
for reference I'm trying to apply this class to it from bootstrap 供参考,我正在尝试从引导程序将此类应用于它
button.close {
-webkit-appearance: none;
padding: 0;
cursor: pointer;
background: transparent;
border: 0;
}
Your css class close
is clashing with the bootstrap close
class. 您的CSS类
close
与引导程序close
类冲突。
Try renaming your css class to something else to see if the problem goes away. 尝试将css类重命名为其他名称,以查看问题是否消失。
If you still want to keep on using this css class name, you will then to override (or reset) the properties that bootstrap close
css class implements. 如果仍要继续使用此CSS类名称,则将覆盖(或重置)引导
close
CSS类实现的属性。
So apparently when you create a button
element in javascript it does not explicitly set the type to button
, you have to add that in yourself. 因此,显然,当您在javascript中创建
button
元素时,没有将类型明确设置为button
,您必须自己添加它。 adding in the line 在行中添加
btn.setAttribute("type", "button");
show the correct css for the button. 显示正确的按钮的CSS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.