Bootstrap 表是如何隐藏的,当使用 javascript 切换可见时,它无法正确显示 [英] Bootstrap table how hidden, when toggled visible using javascript it does not show correctly
问题描述
我有一个引导表.我最初使用 css 隐藏表格行之一.我有一个复选框,如果它被选中,我想显示隐藏的表格行,否则它不应该显示该行.我有它工作,但选择复选框时,现在可见行的格式(宽度)超出了whack(未对齐).我尝试使用此隐藏行的 css(宽度、显示内联表...),但我无法让它工作.
CSS:
#hiddenRow {显示:无;}.合计订单 {填充:10px;背景颜色:#fdfbe4;宽度:95%;边距:0 自动;}.orderTotal h4 {字体粗细:粗体;}.totalOrder {颜色:#ee7a23;字体粗细:粗体;字体大小:18px;}.总金额 {字体粗细:粗体;字体大小:18px;}
表格html:
<h4>订单总数:</h4<table id="tableOrderTotal" class="table tableTotal"><tr><td>项目 1</td><td class="price-1">50</td></tr><td>项目2</td><td class="price-2">13</td></tr><tr><td>Item3</td><td class="price-3">30</td></tr><tr class="摘要"><td class="totalOrder">总计:</td><td id="result" class="totalAmount"></td></tr></tbody>JS 显示隐藏的表格行:
//如果未选中,则从订单总数中隐藏表格行$("input[name='product_CD']").on("click", function() {$("#hiddenRow").toggleClass('show');});
这是选中复选框时行显示方式的屏幕截图.
注意行的宽度和价格列的宽度是如何不对齐的.如果该行最初没有被隐藏,它会很好地预览,并且在检查元素并手动切换 #hiddenRow
display:none
css 时,它也会在浏览器中很好地切换可见/隐藏和关闭.
解决方案 我做了一个 jsfiddle:https://jsfiddle.net/ov7d9rLa/
我认为问题可能是由于使用引导程序和 CSS 进行隐藏/显示之间的斗争.我通过使用引导程序类隐藏"简化了这一点,并使用点击事件切换该类.
<h4>订单总数:</h4><table id="tableOrderTotal" class="table tableTotal"><tr><td>项目 1</td><td class="price-1">50</td></tr><tr id='hiddenRow' class="隐藏"><td>项目2</td><td class="price-2">13</td></tr><tr><td>Item3</td><td class="price-3">30</td></tr><td class="totalOrder">总计:</td><td id="result" class="totalAmount"></td></tr></tbody><button id='toggle' class='btn btn-primary'>切换按钮>
JS:
$("#toggle").on("click", function() {$("#hiddenRow").toggleClass("hidden");});
I have a bootstrap table. I am using css to hide one of the table rows initially. I have a checkbox that I want to show the hidden table row if it is selected, otherwise it should not show the row. I have it working, but when the checkbox is selected, the format (width) of the now visible row is out of whack (not aligned). I tried playing with the css for this hidden row (width, display inline-table...) but I cannot get it to work.
CSS:
#hiddenRow {
display: none;
}
.orderTotal {
padding: 10px;
background-color: #fdfbe4;
width: 95%;
margin: 0 auto;
}
.orderTotal h4 {
font-weight: bold;
}
.totalOrder {
color: #ee7a23;
font-weight: bold;
font-size: 18px;
}
.totalAmount {
font-weight: bold;
font-size: 18px;
}
Table html:
<div class="orderTotal">
<h4>Order Total:</h4
<table id="tableOrderTotal" class="table tableTotal">
<tbody>
<tr>
<td>Item1</td>
<td class="price-1">50</td>
</tr>
<tr id="hiddenRow">
<td>Item2</td>
<td class="price-2">13</td>
</tr>
<tr>
<td>Item3</td>
<td class="price-3">30</td>
</tr>
<tr class="summary">
<td class="totalOrder">Total:</td>
<td id="result" class="totalAmount"></td>
</tr>
</tbody>
</table>
</div>
JS to show hidden table row:
// hide table row from order total if not checked
$("input[name='product_CD']").on("click", function() {
$("#hiddenRow").toggleClass('show');
});
Here is a screenshot of how the row displays when the checkbox is selected.
Notice how the width of the row and the price column is not aligned. It previews fine if the row is not initially hidden and it also toggles visible/hidden fine in a browser when inspecting the element and manually toggling the #hiddenRow
display:none
css on and off.
解决方案 I made a jsfiddle: https://jsfiddle.net/ov7d9rLa/
I think the problem might have been due to fighting between using bootstrap and CSS for hiding/showing. I simplified this by using the bootstrap class "hidden", and toggling that class with the click event.
<div class="orderTotal">
<h4>Order Total:</h4>
<table id="tableOrderTotal" class="table tableTotal">
<tbody>
<tr>
<td>Item1</td>
<td class="price-1">50</td>
</tr>
<tr id='hiddenRow' class="hidden">
<td>Item2</td>
<td class="price-2">13</td>
</tr>
<tr>
<td>Item3</td>
<td class="price-3">30</td>
</tr>
<tr class="summary">
<td class="totalOrder">Total:</td>
<td id="result" class="totalAmount"></td>
</tr>
</tbody>
</table>
</div>
<button id='toggle' class='btn btn-primary'>
Toggle
</button>
JS:
$("#toggle").on("click", function() {
$("#hiddenRow").toggleClass("hidden");
});
这篇关于Bootstrap 表是如何隐藏的,当使用 javascript 切换可见时,它无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
-
使用javascript切换(显示/隐藏)元素;
-
动态添加时Bootstrap切换无法正常显示;
-
角谷歌,地图确实现在可以正确地显示,当它启动时是隐藏;
-
显示/隐藏ajax? javascript切换;
-
显示/隐藏/切换-Javascript/jQuery;
-
在Safari中无法正确隐藏JavaScript显示/隐藏;
-
JavaScript的切换显示/隐藏分区;
-
如何使用Twitter Bootstrap隐藏元素并使用jQuery显示它?;
-
使用JavaScript隐藏/显示表;
-
使用javascript根据选择显示/隐藏(切换)div的显示;
-
当 terminalFocus 时切换侧边栏可见性;
-
Bootstrap崩溃类无法正确切换;
-
如何使用twitter bootstrap 3隐藏元素并使用jQuery显示它?;
-
在NotifyIcon单击时切换表单可见性,而在其他位置单击时隐藏它;
-
当它失去焦点时如何隐藏div?;
-
切换隐藏可见溢出onclick;
-
当滚动条变得可见时,正确地切换页面内容?;
-
Bootstrap 4:隐藏的可见列?;
-
Bootstrap 4:隐藏的可见Cols?;
-
Bootstrap DateTime Picker无法正确显示其在屏幕上的隐藏;
-
如何使用javascript隐藏Bootstrap模态?;
-
如何使用 javascript 隐藏 Bootstrap 模式?;
-
如何使用javascript隐藏Bootstrap模式?;
-
默认情况下隐藏div,并在使用bootstrap进行点击时显示它;
-
使用javascript切换div的可见性;
前端开发最新文章
-
为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?;
-
错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接;
-
如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?;
-
如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?;
-
警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件;
-
如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?;
-
此请求已被阻止;内容必须通过HTTPS提供;
-
资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关);
-
通过HTTPS加载页面但请求不安全的XMLHttpRequest端点;
-
拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。;
热门教程
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆