input点击后,显示DIV,不同的top,会出现在不同的位置解决办法

原始js:

/**
* 参与人输入框事件
**/
$("#boss").click(function(){
var divLocation = $(this).offset();
if (getOs()=="MSIE"){//判断IE 
$("#joinPeople").css({left:divLocation.left, top:divLocation.top -70 +"px"});
}else{
$("#joinPeople").css({left:divLocation.left, top:divLocation.top - 81 +"px"});
}
$("#approverPeople").slideUp("fast");
$("#joinPeople").slideDown("fast");

return false;
});


修改后JS:

/**
* 参与人输入框事件
**/
$("#boss").click(function(){
var divLocation = $(this).offset();
var locationValue = 471-divLocation.top;//多加一个差值即可解决
if (getOs()=="MSIE"){//判断IE 
$("#joinPeople").css({left:divLocation.left, top:divLocation.top -70 +locationValue +"px"});//别忘了此处也要加
}else{
$("#joinPeople").css({left:divLocation.left, top:divLocation.top - 81 +locationValue +"px"});//别忘了此处也要加
}
$("#approverPeople").slideUp("fast");
$("#joinPeople").slideDown("fast");

return false;
});

可以通过以下步骤实现: 1. 在输入框的focus事件中,弹出一个弹框,并将弹框定位到输入框的下方。 2. 在输入框的blur事件中,隐藏弹框。 3. 在弹框中添加一个手动输入框,使其可以接收用户的输入。 4. 在输入框的change事件中,将输入框中的值同步到弹框中的手动输入框中。 示例代码: HTML部分: ``` <div class="input-wrapper"> <input type="text" class="input-box" placeholder="点击输入"> <div class="popup-box"> <input type="text" class="manual-input" placeholder="手动输入"> </div> </div> ``` CSS部分: ``` .input-wrapper { position: relative; } .input-box { width: 200px; height: 30px; border: 1px solid #ccc; padding: 5px; } .popup-box { display: none; position: absolute; top: 40px; left: 0; width: 200px; border: 1px solid #ccc; border-top: none; background-color: #fff; } .manual-input { width: 100%; height: 30px; border: none; padding: 5px; } ``` JavaScript部分: ``` var inputBox = document.querySelector('.input-box'); var popupBox = document.querySelector('.popup-box'); var manualInput = document.querySelector('.manual-input'); inputBox.addEventListener('focus', function() { popupBox.style.display = 'block'; }); inputBox.addEventListener('blur', function() { popupBox.style.display = 'none'; }); inputBox.addEventListener('change', function() { manualInput.value = inputBox.value; }); ``` 注意事项: 1. 弹框的位置可以根据需要进行调整。 2. 如果需要验证用户的手动输入,可以在手动输入框的blur事件中进行验证。如果输入不合法,可以在弹框中显示一个错误提示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学路漫漫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值