如何防止用戶將多行換行插入到文本字段中? 我更喜歡使用jQuery的解決方案。如何防止用戶使用jQuery在textarea中輸入多箇中斷?
更新1:
我已經插入anadeo的代碼到我的代碼如下所示。不幸的是,它不起作用 - 它仍然允許textarea #posttext在一行中多行換行。有人知道怎麼修這個東西嗎?謝謝:)
//Post something
$('#postDiv').on('keydown', '#posttext', function(e) {
if (e.which==13 && !e.shiftKey && $('#posttext').val()!=' Post something...') {
var last = false;
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) {
if (last) { e.preventDefault(); }
last=true;
}else{
last=false;
}
//If not currently loading and enough text typed in, submit
if($('#imageFeedback').html()!=' | Loading...' && $('#posttext').val().length>15){
//Say that it is loading
$('#imageFeedback').css('color','black').css('font-weight','normal').html(' | Loading...');
//Call function to post
post($(this));
return false;
}
}
});
您試過的所有東西到目前爲止? – xbonez
不,說實話我不知道如何解決這個問題。 – weltschmerz