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嗎? –