在表单中,我有一个textarea,我想使用javascript来改变它的价值。 约束是:
我已尝试过此代码,但浏览器被阻止了几秒钟......
$('#edit-body').bind('input propertychange', function()
{
var numbers = ["0","1","2","3","4","5","6","7","8","9"];
var arr = $(this).val().split('');
var news;
for (var i = 0; i < arr.length ; i++)
{
if (arr[i] == "." || arr[i] == ",")
{
if (numbers.indexOf(arr[i-1]) <0 && numbers.indexOf(arr[i+1]) < 0)
{
if (arr[i+1] != ' '){
arr.splice(i, 0, ' ');
}
}
}
}
console.log(arr.toString());
$(this).val(arr.toString());
});
请帮帮我......
答案 0 :(得分:0)
var prevCode = 0;
$('#testing').keypress(function (e) {
$('#kC').val(e.keyCode);
$('#pC').val(prevCode);
if ((prevCode == 44 || prevCode == 46) && (e.keyCode < 49 || e.keyCode > 57)) {
var txtCurr = $('#testing').val();
var lenCurr = txtCurr.length;
var txtNew = txtCurr.substr(0,lenCurr);
$('#testing').val(txtNew + " ");
}
prevCode = e.keyCode;
});