在做项目时遇到了这么一个问题,弹出层时,自动让文本框获得焦点,就是$('id').focus();
可问题是次函数在ie9上好使,在ie8上不好使。后来改为js形式document.getELementById('id').focus()也不好使。
后来看到论坛讨论可以通过这种方式解决:
$("#shadeQRCodeDiv").show();
$('.qrCodeDiv').show('fast', function() {
$("#wfaId").focus();
});
但是项目中用到的是colorbox这个弹出层插件。
没办法,只能自己写一个遮罩了:
#shadeQRCodeDiv{ display: none; position: absolute; top:0px; left:px; width: 100%; height: 100%; background-color: black; z-index:9997; -moz-opacity: 0.15; opacity:0.15; filter: alpha(opacity=15);}
.qrCodeDiv{
border: 1px solid #808080;
overflow:hidden;
zoom: 1;
background: #fff;
}
#qrCodeDiv {
text-align: center;
z-index:9998;
overflow:hidden;
width: 400px;
height: 150px;
left:50%;/*FF IE7*/
top: 50%;/*FF IE7*/
margin-left:-200px!important;/*FF IE7 该值为本身宽的一半 */
margin-top:-75px!important;/*FF IE7 该值为本身高的一半*/
position:absolute;
}
html 放在body标签根下:
<div id="shadeQRCodeDiv"></div>
<div id="qrCodeDiv" style="display: none;" class="qrCodeDiv">
<div class="grayBg">
<div class="toolbar">
<input type="button" οnclick="closeSuccessDiv();" value=" <s:text name='button.cancel'/> " />
</div>
</div>
<div style="margin-top:20px;">
<b>审批单编号:</b> <input type="text" maxlength="50" style="width:200px;" id="wfaId" name="wfaId"/>
</div>
</div>
js代码:
function qrCode(){
$("#shadeQRCodeDiv").show();
$('.qrCodeDiv').show('fast', function() {
$("#wfaId").focus();
});
window.parent.layer();
}
function closeSuccessDiv(){
$("#shadeQRCodeDiv").hide();
$('.qrCodeDiv').hide();
window.parent.remove_layer();
}
$(function(){
$("#wfaId").keydown(function(event){
if(event.keyCode == 13){
document.dataGridForm.action = "<%=request.getContextPath()%>/system/actTask/listTasksByBusinessKey.acti on?wfaId=" + $('#wfaId').val();
document.dataGridForm.submit();
}
});
});