[英]How do I change the button text with glyphicon bootstrap and preserve the order?
I have a search bar and a submit button with text and an icon. 我有一个搜索栏和一个带有文本和图标的提交按钮。 So, I want to replace it for another text and keep the same icon on the right when I click in another button.
因此,我想将其替换为另一个文本,并在单击另一个按钮时在右侧保留相同的图标。 But when I try, the icon comes first and mess the text.
但是当我尝试时,该图标首先出现,并使文本混乱。 How can I maintain the same order and pattern?
如何保持相同的顺序和样式?
I am doing something wrong? 我做错了吗? Please any help will be welcome.
请任何帮助将受到欢迎。 Here goes some images to show what is happening.
这里有一些图像来显示正在发生的事情。
And my function code to replace the text. 和我的功能代码替换文本。
$('#button').click(function(e) {
$("#submit").text("New Search");
$("#submit").addClass('glyphicon glyphicon-search');
});
Live Demo: https://jsfiddle.net/gheleri/mL2btnws/3/ 现场演示: https : //jsfiddle.net/gheleri/mL2btnws/3/
Glyphicons aren't meant to added directly to the button as a class, but added as an inline tag such as i
or span
. 字形符号不是要作为类直接添加到按钮,而是要作为内联标签(例如
i
或span
。
I changed your fiddle to insert as HTML the text with the icon tag. 我更改了您的提琴,将带有icon标记的文本作为HTML插入。 See here: https://jsfiddle.net/mL2btnws/5/
看到这里: https : //jsfiddle.net/mL2btnws/5/
You can wrap the button
text in a separate span
in order to update its value without affecting the rest of the button
. 您可以将
button
文本包装在单独的span
中,以便在不影响button
其余部分的情况下更新其值。
I updated the fiddle: https://jsfiddle.net/twernt/mL2btnws/12/ 我更新了小提琴: https : //jsfiddle.net/twernt/mL2btnws/12/
Here is the modified HTML: 这是修改后的HTML:
<button id="submit" class="btn btn-success" type="submit">
<span class="label">Search!</span>
<span class="glyphicon glyphicon-search"></span>
</button>
Here is the modified JavaScript: 这是经过修改的JavaScript:
$('#button').click(function(e) {
$("#submit .label").text("New Search");
});
<button
className=" delete-button glyphicon glyphicon-trash"
onClick=() =>
/>
and in you css file 在你的css文件中
.delete-button {
padding: 0;
border: none;
background: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.