正在从 Javascript 中的文本框中删除选项卡 space
Removing tab space from text box in Javascript
如何从文本框中删除制表符 space 值。我的功能代码是::
function validTitle() {
if (window.document.all.dDocTitle.value == "") {
alert("Please enter the Title");
window.document.all.dDocTitle.focus();
return false;
}
return true;
}
我想再添加 1 个条件,用于删除文本框中的制表符 space,以获取使用 window.document.all.dDocTitle.value
捕获的值
您可以使用 String.trim() 函数 () :
function validTitle() {
// just a remark: use document.getElementById('textbox_id') instead, it's more supported
var textBox = window.document.all.dDocTitle;
if (!(typeof textBox.value === 'string') || !textBox.value.trim()) { // if textbox contains only whitespaces
alert("Please enter the Title");
textBox.focus();
return false;
}
// remove all tab spaces in the text box
textBox.value = textBox.value.replace(/\t+/g,'');
return true;
}
如何从文本框中删除制表符 space 值。我的功能代码是::
function validTitle() {
if (window.document.all.dDocTitle.value == "") {
alert("Please enter the Title");
window.document.all.dDocTitle.focus();
return false;
}
return true;
}
我想再添加 1 个条件,用于删除文本框中的制表符 space,以获取使用 window.document.all.dDocTitle.value
捕获的值您可以使用 String.trim() 函数 () :
function validTitle() {
// just a remark: use document.getElementById('textbox_id') instead, it's more supported
var textBox = window.document.all.dDocTitle;
if (!(typeof textBox.value === 'string') || !textBox.value.trim()) { // if textbox contains only whitespaces
alert("Please enter the Title");
textBox.focus();
return false;
}
// remove all tab spaces in the text box
textBox.value = textBox.value.replace(/\t+/g,'');
return true;
}