【问题标题】:How to place glyphicon inside a placeholder in a input form using bootstrap如何使用引导程序将 glyphicon 放置在输入表单中的占位符内
【发布时间】:2015-03-08 10:24:13
【问题描述】:

我正在尝试通过引导程序使用 placeholder 在输入表单中放置一个字形图标。

但结果是它在输入表单中显示代码而不是图标。

这是我的代码:


<input type="text" class="form-control" placeholder="<span class='glyphicon glyphicon-search'></span>search">

输出:

显示为

<span class="glyphicon glyphicon-search">search

在输入表单中。


对不起,不清楚的问题

实际上,当我点击输入表单并输入一些文本时,字形图标应该隐藏起来,因为我们将其放置在占位符中。

提前致谢。

【问题讨论】:

标签: html css twitter-bootstrap


【解决方案1】:

这样试试

 <!DOCTYPE html>
<html>
<title>Timer</title>
<head>
<link href="css/bootstrap.css" type="text/css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script>
        jQuery(function(){
            $('#exampleInputAmount').blur(function(){
                var textValue = $(this).val(); // GETTING TEXT BOX VALUE
                if(textValue != '') {
                    $('.glyphicon-search').parent().hide(); // HIDDING DIV IF TEXT BOX IF NOT EMPTY
                } else {
                    $('.glyphicon-search').parent().show(); // SHOWING DIV IF TEXT BOX IF EMPTY
                }
            });
        });
    </script>
</head>
<body>
<form class="form-inline">
  <div class="form-group">
    <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
    <div class="input-group">
      <div class="input-group-addon"><span class="glyphicon glyphicon-search"></div>
      <input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
      <div class="input-group-addon"><span class="glyphicon glyphicon-search"></div>
    </div>
  </div>
</form>
</body>
</html>

此外,您可以参考下面的 URL,它提供了许多引导相关问题的语法和格式。

http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-lists.php

【讨论】:

  • 嘿,我得到了文本形式的字形图标,谢谢。但是当我们在输入表单中输入文本时,我需要隐藏字形图标(与占位符相同)。
  • 因为你必须使用一些jquery的东西,可以吗?
  • stackoverflow.com/questions/8987428/image-placeholder 这也可能有帮助,如果你对 jQuery 的东西没问题,请告诉我
  • 对不起,我不懂 jquery,但我正在尝试使用示例代码。
猜你喜欢
  • 1970-01-01
  • 2019-01-26
  • 2020-11-20
  • 2017-11-26
  • 1970-01-01
  • 2018-12-26
  • 2020-11-04
  • 1970-01-01
  • 2015-12-17
相关资源
最近更新 更多