Bài đăng

Đang hiển thị bài đăng từ tháng 2 3, 2008

Cắt bỏ khoản trắng trong javascript

function checkForm(){ var rs = false; document.mainform.editor.value = editor.getHTML(); if(document.getElementById('servicename')!=null){ var str = document.getElementById('servicename').value; str = trim(str); if((str=="")||((str == null))){ alert('Please! input to service name!'); return false; } else document.getElementById('servicename').value = str; } } function trim(str) { if(!str || typeof str != 'string') return null; return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); } String.prototype.trim = function() { if(!this || typeof this != 'string') return null; return this.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); } _form id="mainform"> _textarea id="editor&quo