この記事では、JSのTRIM関数と互換性がないIE7とIE8を実装するカスタム関数の方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
<html> <head> <title> test> </title> <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> <center> <input id = "test" type = "text"/> <input id = "しかし" type = "button" value = "check" onclick = "check();"/> </center> </body> </html> </html> </html>これにより、JSがIEでトリムをサポートしていない問題が解決します。
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。