Bootstrap同时切换按钮图标和文本(Bootstrap toggle button icon and text at the same time)
我正在用
Jquery
使用Bootstrap 3
。 我有一个在span标签中包含图标的按钮(使用引导程序的glypicon)<button id="swapArchived" class="btn btn-default btn-sm showArchived"> <span class="glyphicon glyphicon-road"></span> Show Archived </button>
我想单击时更改图标和文字。 有没有更好的方法,除了,
$('#swapArchived').on('click', function () { var $el = $(this); if($el.hasClass('showArchived')) { $el.html('<span class="glyphicon glyphicon-fire"></span> Show Incomplete'); } else { $el.html('<span class="glyphicon glyphicon-road"></span> Show Archived'); } $el.toggleClass('showArchived'); });
我很好奇我是否可以同时切换按钮文本和span类。 尽量避免每次点击都要写满量程。
谢谢-
I am using
Bootstrap 3
withJquery
. I have a button that contains an icon in a span tag.(using glypicon of bootstrap)<button id="swapArchived" class="btn btn-default btn-sm showArchived"> <span class="glyphicon glyphicon-road"></span> Show Archived </button>
I want to change the icon and text when clicked. Is there any better way other than,
$('#swapArchived').on('click', function () { var $el = $(this); if($el.hasClass('showArchived')) { $el.html('<span class="glyphicon glyphicon-fire"></span> Show Incomplete'); } else { $el.html('<span class="glyphicon glyphicon-road"></span> Show Archived'); } $el.toggleClass('showArchived'); });
I was curious whether I can toggle button text and span class at the same time. Trying to avoid writing span on every click.
Thanks-
原文:https://stackoverflow.com/questions/19898599
更新时间:2022-02-28 11:02
最满意答案
您可以使用包含两个单元格的表格。 将
input
字段放在左侧单元格中,将图像放在右侧单元格中。 喜欢这个:<input type="text" style="width:95%" /><br /><br /> <input type="text" style="width:95%" /><br /><br /> <table> <tr> <td><input type="text" style="width:95%" /> <br /> <br /> <input type="text" style="width:95%" /> </td> <td><img src="http://icons.iconarchive.com/icons/martin-berube/people/256/baby-icon.png" /></td> </tr> </table> <br /> <textarea style="width:95%"></textarea>
You could use a table with two cells. Put the
input
fields in the left cell, and the image in the right cell. Like this:<input type="text" style="width:95%" /><br /><br /> <input type="text" style="width:95%" /><br /><br /> <table> <tr> <td><input type="text" style="width:95%" /> <br /> <br /> <input type="text" style="width:95%" /> </td> <td><img src="http://icons.iconarchive.com/icons/martin-berube/people/256/baby-icon.png" /></td> </tr> </table> <br /> <textarea style="width:95%"></textarea>
相关问答
更多-
包含Div的图像(Containing an Image with Div)[2022-01-18]
你可以尝试这样 - #col1{ float: left; height: 500px; text-align: center; width: 33%; border-width: 1px; border-style: dotted; position: relative;/*add this*/ } #col1 img{ position: absolute; left:0; right:0; top:0; b ... -
如何内联div(how to Inline the div)[2023-08-28]
根据我的理解,这是正在发生的事情: Your content [SQUARE] More content 代替 Your content [SQUARE] more content 你试过display: inline-block; 另外,检查包含div是否能够将所有这些内容整合到一行中。 编辑:请记住display: block是(大多数)元素的DEFAULT属性,这将强制它们在新行上。 因此,要更改此设置,您可以通过设置自定义display: property来自行覆盖默认值。 有关它们的列表,请访 ... -
将preselect类移到innerdiv 。 做一些这些css修改: img { width: 100%; height: 100%; } .preselect{ background: lightgreen; border: 1px solid black; } 结帐小提琴 Move the preselect class to the innerdiv. Make some of these css modifications: img { width: 100%; hei ...
-
Html内联div对齐问题(Html inline div alignment issue)[2023-09-16]
iyiakşamlar:)你可以删除div's,在单选按钮内创建类,并将它们完全放入每行的容器中。 现场演示a2a3尝试
然后 function handleFileSelect(evt) { var $fileUpload ...如何插入图像内联与div而不降低以下div(how do i insert an Image inline with div without lowering the following div)[2023-05-15]
您可以使用包含两个单元格的表格。 将input字段放在左侧单元格中,将图像放在右侧单元格中。 喜欢这个: