ไม่มีปัญหาในการใช้ฟังก์ชั่นการตัดแต่งของ JavaScript ภายใต้ Firefox
<ภาษาสคริปต์ = "JavaScript"> var test1 = "AA"; test1 = test1.toString (); test1 = test1.trim (); </script>
ไม่มีปัญหาในการใช้สิ่งนี้ภายใต้ Firefox แต่จะมีการรายงานใน IE
จากนั้นเราสามารถแก้ไขได้
string.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, "");}เพิ่มประโยคนี้ลงบนหัวและสามารถทำงานได้ภายใต้ IE และ FF
<script language = "javascript"> string.prototype.trim = function () {return thinplace (/(^/s*) | (/s*$)/g, "");} var test1 = "aa"; test1 = test1.toString (); test1 = test1.trim (); </script>วิธีการที่จัดทำโดย jQuery:
<! doctype html> <html> <head> <script src = "http://code.jquery.com/jQuery-latest.js"> </script> </head> <body> <button> แสดงตัวอย่าง </button> <print> $ ("ปุ่ม") ""); </script> </body> </html>