2014-04-07 59 views
-1

嗨,我需要實現這個破折線在這裏工作,因爲你可以輸入enter,但是在你再次輸入沒有給出破折線。允許「輸入」鍵工作,但沒有給出破折線

我使這個小提琴http://jsfiddle.net/FPN9w/

這裏是JS代碼。

$(function() { 
    //you have to escaped the - character in a character class 
    var cleanRx = /[^a-zA-Z0-9 áéíóúÁÉÍÓÚÜüñѨ´,.¿?%&$!¡ªº#"()\-_\/]/g; 

    $('#title').keyup(function (e) { 
     var which = e.which; 

     //avoid useless replacements when <- and -> keys are pressed 
     if (which === 39 || which === 37) return; 

     this.value = this.value.replace(cleanRx, ''); 

    }).trigger('keyup'); //perform replacement on initial content (remove if uneeded) 

    $('#description1').keyup(function (e) { 
     var which = e.which; 

     //avoid useless replacements when <- and -> keys are pressed 
     if (which === 39 || which === 37 || which === 13) return; 

     this.value = this.value.replace(cleanRx, ''); 

    }).trigger('keyup'); //perform replacement on initial content (remove if uneeded) 

}); 
+0

你到底想達到什麼目的? –

+1

可能會幫助你http://jsfiddle.net/FPN9w/1/,在這裏使用'/ [^ a-zA-Z0-9áéíóúÉÉúÓÚÜüñѨ',.¿?%&$!¡ºº#「()\ n \ r \ -_ \//]/g;' – Satpal

+0

Satpal請讓正式答案,你的小提琴正是我需要的=)欣賞!!! –

回答

1

添加該代碼JS

$('#description1').keydown(function(event){ 
    if(event.keyCode == 13) { 
     event.preventDefault(); 
     return false; 
    } 
}); 

這是你更新的jsfiddle http://jsfiddle.net/pratbhoir/FPN9w/3/

+0

謝謝,也許我問錯了問題..我需要輸入鍵的工作,我意思是添加breakline ..在你添加的小提琴中,我不能添加一個breakline ..謝謝!! –

相關問題