如何从文本框中删除制表符空格值。我的功能代码是::
function validTitle() {
if (window.document.all.dDocTitle.value == "") {
alert("Please enter the Title");
window.document.all.dDocTitle.focus();
return false;
}
return true;
}
我想再添加 1 个条件,用于删除文本框中的制表符空间,以获取使用 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;
}
关于javascript - 从 Javascript 文本框中删除制表符空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32421988/