简体   繁体   English

Javascript trimAll()似乎不起作用

[英]Javascript trimAll() doesn't seem to work

When i executed this, 当我执行这个时

var a = trimAll(document.getElementById("txt_msg").value);

When i inspected through web developer toolbar I got the Error : trimAll is not defined .. 通过Web开发人员工具栏检查时,出现错误trimAll is not defined ..

Any suggestion... 任何建议...

According to the latest edition of the ECMAScript spec, trimAll is not a standard Javascript function. 根据ECMAScript规范的最新版本, trimAll不是标准的Javascript函数。 Either it is a browser-specific extension, or a third-party library. 它是特定于浏览器的扩展程序,还是第三方库。

Exercise due caution if you want your Javascript / website to work in all browsers. 如果您希望Javascript /网站在所有浏览器中都能正常运行,请务必当心。

As others have mentioned, the error is indicating that the trimAll() function has not been defined. 正如其他人提到的那样,该错误表明未定义trimAll()函数。 As trimAll() is not a standard JavaScript function, you would need to write one named trimAll() in order to call it. 由于trimAll()不是标准的JavaScript函数,因此您需要编写一个名为trimAll()的函数才能对其进行调用。

There are many ways to write a string trimming function. 有许多编写字符串修剪函数的方法。 Some functions are compact, some are easy to read, others are blazing fast . 有些功能紧凑,有些易于阅读,有些则很快

It's worth keeping in mind that native JavaScript trim is supported in ECMAScript 5 . 值得注意的是ECMAScript 5支持本机JavaScript修剪 I suspect the intention of your trimAll() function call would be the same functionality as trim(). 我怀疑您的trimAll()函数调用的意图将与trim()相同。

So, if you plan to write your own trim function, it might be worth while checking for the existence of a native trim and using that in preference to your own string trimming method if you prefer. 因此,如果您打算编写自己的修整函数,那么在检查是否存在本机修整并且如果愿意的话,优先使用该函数而不是自己的字符串修整方法是值得的。

Here's a trimAll function that might help: 这是一个trimAll函数,可能会有所帮助:

http://www.jslab.dk/library/String.trimAll http://www.jslab.dk/library/String.trimAll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM