[英]How to add Font Awesome icon into <input> button?
I'm trying to add an <input type="reset">
with a Font Awesome icon. 我正在尝试使用Font Awesome图标添加
<input type="reset">
。
I can achieve this with a hyperlink or button but if I go down that route I need to use jQuery/JS to clear the form, which I'm trying to avoid for the time being. 我可以通过超链接或按钮来实现这一点,但如果我沿着那条路走下去,我需要使用jQuery / JS来清除表单,我暂时试图避免这种情况。
I'm curious to whether it's possible to achieve the same results. 我很想知道是否有可能取得同样的结果。 Please see the JSFiddle to see what I mean.
请看JSFiddle看看我的意思。
Input Reset:
<input type="reset" class="btn btn-warning" value=""><i class="fa fa-times"></i> Clear</input>
<br/>
<br/>
Button:
<button class="btn btn-warning"><i class="fa fa-times"></i> Clear</button>
<br/>
<br/>
Anchor:
<a href="#" class="btn btn-warning"><i class="fa fa-times"></i> Clear</a>
If there's no other way I will implement a jQuery solution. 如果没有其他方法我将实现jQuery解决方案。
<input>
is self-closing tag, it's not allowed to have any other elements inside it. <input>
是自动关闭标记,不允许在其中包含任何其他元素。
Here are all the 3 possible options of doing it as inline icon. 以下是将其作为内联图标的所有3种可能选项。
1. wrap the <i>
and <input>
button into a <span>
tag, with some custom styles. 1.将
<i>
和<input>
按钮包装到带有一些自定义样式的<span>
标记中。
<span class="btn btn-warning">
<i class="fa fa-times"></i> <input type="reset" value="Clear"/>
</span>
span > i {
color: white;
}
span > input {
background: none;
color: white;
padding: 0;
border: 0;
}
2. use <button type="reset">
- recommended . 2.使用
<button type="reset">
- 推荐 。
<button class="btn btn-warning" type="reset">
<i class="fa fa-times"></i> Clear
</button>
3. use <a>
anchor tag + javascript 3.使用
<a>
锚标签+ javascript
<a href="javascript:document.getElementById('myform').reset();" class="btn btn-warning">
<i class="fa fa-times"></i> Clear
</a>
https://jsfiddle.net/a6s58Luj/3/ https://jsfiddle.net/a6s58Luj/3/
<input type="reset" class="NEWCLASS btn btn-warning" value=" Clear" />
By adding value=" Clear"
you can add the X icon. 通过添加
value=" Clear"
您可以添加X图标。 f00d
is the icon HEX/whatever, which I got from inspecting the elements (checking the ::before
's content). f00d
是图标HEX / whatever,我从检查元素(检查::before
的内容)得到的。 You might have to look into some additional styling, but it will work. 您可能需要考虑一些额外的样式,但它会起作用。 Just remember to set the font.
只记得设置字体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.