如何将自定义按钮添加到引导程序输入

发布于 2025-01-24 01:57:18 字数 506 浏览 0 评论 0原文

我能找到的最接近的是:

input[data-icon] {
  padding-left: 25px;
  background: url("https://static.thenounproject.com/png/101791-200.png") no-repeat left;
  background-size: 20px;
} 

“搜索按钮”

但是一旦出现jQuery的验证图标,将删除此图标。

我知道Bootstrap输入组可以预处和附加图标,但是这些图标已经保留用于其他用法(在我的项目中)。

此外,我希望添加的图标也可以单击。添加为背景图像不起作用。

The closest I can find is:

input[data-icon] {
  padding-left: 25px;
  background: url("https://static.thenounproject.com/png/101791-200.png") no-repeat left;
  background-size: 20px;
} 

Search Button

But this icon will be removed once the JQuery's validation icon appears.

I knew Bootstrap input group can prepend and append icons, but those icons had already been reserved for other usage (in my project).

Besides, I wish the added icon is clickable as well. Added as a background image doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2025-01-31 01:57:18

在这里,你去...

这正是您想要的。图标也可单击。请参阅下面的摘要。

function myFunction() {
  alert("I am clickable!");
}
.input-icon:hover {
  cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
  <script src="https://use.fontawesome.com/releases/v5.15.3/js/all.js" data-auto-replace-svg="nest"></script>

</head>

<body>

  <div class="input-group flex-nowrap">
    <span class="input-group-text" id="addon-wrapping">@</span>
    <div class="input-wrapper d-flex align-items-center position-relative">
      <input type="text" class="form-control ps-4" id="my-input" placeholder="E-mail" aria-label="Username" aria-describedby="addon-wrapping">
      <label for="my-input" class="fa fa-user input-icon position-absolute px-2" onclick="myFunction()"></label>
    </div>
  </div>

</body>

</html>

Here you go...

This is exactly what you want. The icon is also clickable. See the snippet below.

function myFunction() {
  alert("I am clickable!");
}
.input-icon:hover {
  cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
  <script src="https://use.fontawesome.com/releases/v5.15.3/js/all.js" data-auto-replace-svg="nest"></script>

</head>

<body>

  <div class="input-group flex-nowrap">
    <span class="input-group-text" id="addon-wrapping">@</span>
    <div class="input-wrapper d-flex align-items-center position-relative">
      <input type="text" class="form-control ps-4" id="my-input" placeholder="E-mail" aria-label="Username" aria-describedby="addon-wrapping">
      <label for="my-input" class="fa fa-user input-icon position-absolute px-2" onclick="myFunction()"></label>
    </div>
  </div>

</body>

</html>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文