我的应用程序在chrome和iexplorer上的函数正常,但在firefox中没有。
如果他没有回答请求,我希望他回复输入。
代码示例:
$('#txtTime').blur(function() {
var days = parseInt($('#txtTime').val());
if (days < 1 || days > 90) {
$('#msg_days').html('* Entry value > 0 and < 90').css('color', 'red');
$('#msg_date').html('');
$('#txtTime').focus();
console.log(days);
} else {
var hj = new Date();
var prazo = new Date(hj.setDate(hj.getDate() + days));
$('#msg_days').html('Previsão ').css('color', 'black');
$('#msg_date').html(prazo.toLocaleDateString());
}
});
.input {
width: 100px;
border-radius: 5px;
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>Prazo:
<input class="input" type="number" min="1" max="90" id="txtTime" name="txtTime" value="45">
</label>
<span id="msg_days"></span><span id="msg_date"></span>
<br><br>
<label>Próximo:
<input class="input" type="text" id="txtProx" name="txtProx">
</label>
答案 0 :(得分:1)
强制关注输入似乎可以在firefox中使用。
$('#txtTime').blur(function() {
var days = parseInt($('#txtTime').val());
if (days < 1 || days > 90) {
$('#msg_days').html('* Entry value > 0 and < 90').css('color', 'red');
$('#msg_date').html('');
$('#txtTime').focus();
console.log(days);
} else {
var hj = new Date();
var prazo = new Date(hj.setDate(hj.getDate() + days));
$('#msg_days').html('Previsão ').css('color', 'black');
$('#msg_date').html(prazo.toLocaleDateString());
}
}).on('input', function(e) {
$(e.target).focus();
});
&#13;
.input {
width: 100px;
border-radius: 5px;
padding: 5px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>Prazo:
<input class="input" type="number" min="1" max="90" id="txtTime" name="txtTime" value="45">
</label>
<span id="msg_days"></span><span id="msg_date"></span>
<br><br>
<label>Próximo:
<input class="input" type="text" id="txtProx" name="txtProx">
</label>
&#13;
答案 1 :(得分:0)
解决
开关
$('#txtTime').focus();
每
setTimeout(function() {
$("#txtTime").focus();
}, 0);
$('#txtTime').blur(function() {
var days = parseInt($('#txtTime').val());
if (days < 1 || days > 90) {
$('#msg_days').html('* Entry value > 0 and < 90').css('color', 'red');
$('#msg_date').html('');
setTimeout(function() {
$("#txtTime").focus();
}, 0);
console.log(days);
} else {
var hj = new Date();
var prazo = new Date(hj.setDate(hj.getDate() + days));
$('#msg_days').html('Previsão ').css('color', 'black');
$('#msg_date').html(prazo.toLocaleDateString());
}
});
.input {
width: 100px;
border-radius: 5px;
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>Prazo:
<input class="input" type="number" min="1" max="90" id="txtTime" name="txtTime" value="45">
</label>
<span id="msg_days"></span><span id="msg_date"></span>
<br><br>
<label>Próximo:
<input class="input" type="text" id="txtProx" name="txtProx">
</label>