HTML:<enter>停止按键时工作
<div class="col-md-10 col-sm-10 col-xs-10">
{{ form_widget(experienceForm.description, {
'attr': {
'class': 'form-control field-max-length field-max-length field-line-length',
'rows': 6
}
})}}
</div>
handleChangeLineCounter = function() {
$('.field-line-length').keyup(function (e) {
e.preventDefault();
var countLineNum = (this.value.match(/\n/g)||[]).length;
console.log(countLineNum);
checkEnterKey ($(this), 7, countLineNum);
});
}
function checkEnterKey (getVarName, maxLine, countLine) {
var msg2 = maxLine - countLine +' lignes restantes,';
if ((maxLine - countLine) === 1 || (maxLine - countLine) === 0) {
msg2 = maxLine - countLine +' ligne restante,';
}
getVarName.keypress(function(e) {
if(e.which === 13) {
if ((maxLine - countLine) < 1) {
return false;
}
else if ((maxLine - countLine) > 0) {
return true;
}
}
});
$('.counter-msg-2').remove();
getVarName.after('<span class="counter-msg-2 m-r-5"><span class="counter_msg_2">' + msg2 + '</span></span>');
}
从上面的代码,在功能checkEnterKey()
,当(maxLine - countLine
)为0时,我按下删除键或退格键,然后再按回车键,该键停止加工。 相反如果(maxLine - countLine
)未达到0,我按删除键或退格键,然后再次按回车键,该键工作。 当我达到(maxLine - countLine) = 0
时,如何使输入键工作?
您是否尝试在返回false时更改为'maxLine - countLine <0'? – Justinas
我做了,问题仍然存在,我试过<= 0,我甚至将限制改为-2而不是0,这次,当它达到-2时,回车键停止工作 – space110
您可以包含HTML吗? –