Artikel ini menjelaskan metode fungsi khusus untuk mengimplementasikan IE7 dan IE8 yang tidak kompatibel dengan fungsi trim di JS. Bagikan untuk referensi Anda. Metode implementasi spesifik adalah sebagai berikut:
<html> <head> <title> tes </iteme> <script type = "text/javascript"> string.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, ""); } function check () {var str = document.geteLementById ("test"). value; alert (str.trim ()); } </script> </head> <body> <senter> <input id = "test" type = "text"/> <input id = "tetapi" type = "tombol" value = "check" onclick = "check ();"/> </center> </body> </html>Ini memecahkan masalah bahwa JS tidak mendukung trim pada IE.
Saya harap artikel ini akan membantu pemrograman JavaScript semua orang.