0
私はこのボックスを8ワードに制限しようとしていますが、スペースを "カンマスペース"に置き換えても 誰かがこれをどうすればいいのかアドバイスできますか?スペースは作業を置き換えますが、両方を置き換えません。同じ入力ボックスの2つのJquery
はここ
は私のHTMLは
<input name="input_4" type="text" id="input_10_4" size="100" />
で、ここに私のjQueryのここ
jQuery("#input_10_4").keyup(function() {
var textValue = $(this).val();
textValue = textValue.replace(/ /g, ", ");
$(this).val(textValue);
});
jQuery(document).ready(function() {
$("#input_10_4").keyup(function() {
var content = $("#input_10_4").val(); //content is now the value of the text box
var words = content.split(/\s+/); //words is an array of words, split by space
var num_words = words.length; //num_words is the number of words in the array
var max_limit = 8;
if (num_words > max_limit) {
alert("Exceeding the max limit");
var lastIndex = content.lastIndexOf(" ");
$("#input_10_4").val(content.substring(0, lastIndex));
$('#remainingChars').text('Limit Exceeding');
return false;
} else {
$('#remainingChars').text(max_limit + 1 - num_words + " words remaining");
}
});
});