繁体   English   中英

在文本框后添加图像而不移动它

[英]Add image after textbox without moving it

我想在文本框后显示图像以进行验证(勾选和交叉),但是当我显示或隐藏它们时,文本框会垂直向上或向下跳跃

这是HTML

<table cellspacing="20">
<tr>
    <td>Username</td>
    <td>*<input type="text" id="username" class="required" name="user.username" value="" size="30" />
    </td>
</table>

和JavaScript

window.onload = function(){

$('input.required').after('<img class="toggle"></img>').next().hide();

$('input.required').blur(function() {
 if ($(this).val().length == 0) {
    $(this)
    .addClass('error')
    .next()
    .attr('src','images/unchecked.gif').fadeIn()

 }
 else
 {
    $(this).next().attr('src','images/checked.gif').fadeIn()
 }

我希望文本框保持固定,并且不要继续切换图像

通过css()将图像的visibility设置为hidden而不是使用hide()

visibility:hidden隐藏元素,但该元素仍会占用其空间。 hide()将显示设置为无,元素不占用空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM