https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_trim_polyfill ' Puoi anche utilizzare la soluzione di sostituzione sopra per aggiungere una funzione di ritaglio al JavaScript String.prototype: https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_trim_polyfill <!DOCTYPE html> <html> <body> <h2>JavaScript String.trim()</h2> <p>IE 8 does not support String.trim(). To trim a string you can use a polyfill.</p> <script> if (!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }; }; var str = " Hello World! "; alert(str.trim()); </script> </body> </html> |