如何将图像添加到HTML输入小部件?

如何将图像添加到HTML输入小部件?,html,css,forms,html-input,Html,Css,Forms,Html Input,例如,如果你去 在用户名中键入“john”,右侧会出现一个红色的感叹号。忘记我知道如何使用JavaScript,如何将图像输入到文本输入中?您可以将图像作为输入元素背景的一部分。您可以将图像作为输入元素背景的一部分。这是一个CSS 例: 您还可以使用CSS指定图像。这是一个CSS 例: 您还可以使用CSS指定图像。如果您不想使用背景图像(因此可以使用精灵图标,如jQuery UI),可以使用绝对定位覆盖图标 示例(未测试): 如果不想使用背景图像(因此可以使用精灵图标,如jQuery UI),

例如,如果你去


在用户名中键入“john”,右侧会出现一个红色的感叹号。忘记我知道如何使用JavaScript,如何将图像输入到文本输入中?

您可以将图像作为输入元素背景的一部分。

您可以将图像作为输入元素背景的一部分。

这是一个CSS

例:

您还可以使用CSS指定图像。

这是一个CSS

例:


您还可以使用CSS指定图像。

如果您不想使用背景图像(因此可以使用精灵图标,如jQuery UI),可以使用绝对定位覆盖图标

示例(未测试):


如果不想使用背景图像(因此可以使用精灵图标,如jQuery UI),可以使用绝对定位覆盖图标

示例(未测试):


以下是如何以相同的方式显示图像,即在右侧显示图像,并将其安装在框内:

<style type="text/css">
.input_error_bg {
    background-image: url("myimage.png");
    background-size: contain;
    -moz-background-size: contain;
    -webkit-background-size: contain;
    -khtml-background-size: contain;
    -o-background-size: contain;
    background-position: right 50%;
    background-repeat: no-repeat;
}
.input_bg {
    background: none;
}
</style>

<form action="signup.php" method="POST">
<input class="input_error_bg" type="text" />
</form>

.输入错误{
背景图片:url(“myimage.png”);
背景尺寸:包含;
-moz背景大小:包含;
-webkit背景大小:包含;
-khtml背景大小:包含;
-o-背景尺寸:包含;
背景位置:右50%;
背景重复:无重复;
}
.input_bg{
背景:无;
}
根据需要使用javascript更改类名


希望这对您有所帮助:)

以下是您如何以相同的方式显示图像,即在右侧显示图像,并将其安装在框内:

<style type="text/css">
.input_error_bg {
    background-image: url("myimage.png");
    background-size: contain;
    -moz-background-size: contain;
    -webkit-background-size: contain;
    -khtml-background-size: contain;
    -o-background-size: contain;
    background-position: right 50%;
    background-repeat: no-repeat;
}
.input_bg {
    background: none;
}
</style>

<form action="signup.php" method="POST">
<input class="input_error_bg" type="text" />
</form>

.输入错误{
背景图片:url(“myimage.png”);
背景尺寸:包含;
-moz背景大小:包含;
-webkit背景大小:包含;
-khtml背景大小:包含;
-o-背景尺寸:包含;
背景位置:右50%;
背景重复:无重复;
}
.input_bg{
背景:无;
}
根据需要使用javascript更改类名

希望这有帮助:)

<style type="text/css">
.input_error_bg {
    background-image: url("myimage.png");
    background-size: contain;
    -moz-background-size: contain;
    -webkit-background-size: contain;
    -khtml-background-size: contain;
    -o-background-size: contain;
    background-position: right 50%;
    background-repeat: no-repeat;
}
.input_bg {
    background: none;
}
</style>

<form action="signup.php" method="POST">
<input class="input_error_bg" type="text" />
</form>