IE str.trim() 不兼容问题解决方法
本文实例分析了javascript在IE下trim函数无法使用的解决方法:
首先,javascript的trim函数在firefox或者chrome下面使用没有问题:
|
1
2
3
4
5
|
<script language="javascript"> var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim(); </script> |
在火狐或者谷歌下这样用没有问题, 但是在IE下就报错!
解决办法是:
<script language="javascript">String.prototype.trim=function(){returnthis.replace(/(^\s*)|(\s*$)/g,"");}vartest1 =" aa ";test1 = test1.toString();test1 = test1.trim();</script>
<!DOCTYPE html><html><head><script src="http://code.jquery.com/jquery-latest.js"></script></head><body><button>Show Trim Example</button><script>$("button").click(function() {varstr =" lots of spaces before and after ";alert("'"+ str +"'");str = jQuery.trim(str);alert("'"+ str +"' - no longer");});</script></body></html>
希望本文可以帮助到你。
IE str.trim() 不兼容问题解决方法的更多相关文章
- JavaScript在IE和Firefox(火狐)的不兼容问题解决方法小结 【转】http://blog.csdn.net/uniqer/article/details/7789104
1.兼容firefox的 outerHTML,FF中没有outerHtml的方法. 代码如下: if (window.HTMLElement) { HTMLElement.prototype.__de ...
- JavaScript在IE和Firefox的不兼容问题解决方法总结
1.兼容Firefox的 outerHTML,Firefox中没有outerHtml的方法. if (window.HTMLElement) { HTMLElement.prototype.__def ...
- FCKEditor在IE10下的不兼容问题解决方法
环境介绍:FCKEditor 版本 2.x.x 问题:IE10 下FCKEditor不兼容,显示不出来 关键词:不同于其他方法之处是第一个关键点,其他网友的正则表达式不对 解放方法:(可以直接< ...
- Jmeter与搜狗输入法、百度输入法不兼容问题解决方法
问题:Jmeter 3.3.4.0等版本与最新版搜狗输入法.百度输入法不兼容,输入法悬浮窗口无法实时显示出来. 解决方法:换用微软拼音输入法即可. 微软拼音输入法: 官方下载链接: https://w ...
- inline-block和text-indent在IE6,IE7下同时使用的兼容问题解决方法
在实际应用中,考虑到seo,很多button,icon都要用到inline-block和text-indent来处理,例如: <a href="#">Button< ...
- js Date()日期函数浏览器兼容问题解决方法
一般 直接new Date() 是不会出现兼容性问题的,而 new Date(datetimeformatstring) 常常会出现浏览器兼容性问题,为什么,datetimeformatstring中 ...
- xcode10不兼容问题解决方法,framework编译脚本
XCode10报错:Build/Intermediates.noindex/XCBuildData/build.db": disk I/O error 更改-scheme 为-target ...
- 正则表达式去除字符串左右空格函数 调用方法是,str.Trim();
正则表达式去除字符串左右空格函数 调用方法是,str.Trim(); String.prototype.Trim = function() { return this.replace(/(^\s*)| ...
- 各种浏览器兼容trim()的方法
一.利用while方法解决 function trim(str) { while (str[0] == ' ') { str = str.slice(1); } while (str[str.leng ...
随机推荐
- ecshop模板修改后还原的原因
转:http://www.ecmoban.com/article-1693.html 有些刚接触 ecshop的朋友会遇到这样的问题:今天刚修改好的一个地方,等过一段时间后台操作了一会之后发现修改过的 ...
- Centos6.4 为用户添加sudo功能
sudo即super user do,以超级管理员的方式运行命令.使用时,只需在命令最前面加上sudo即可. 要为用户添加sudo功能,需要修改sudo的配置文件: vi /etc/sudoers ( ...
- (转载)在mysql中,column 'id' in field list is ambiguous
(转载)http://blog.chinaunix.net/uid-20665047-id-3137284.html column 'id' in field list is ambiguous 这个 ...
- ASP.NET MVC 中将FormCollection与实体间转换方法 (转)
将Action动作中传递的FormCollection转变成对应的实体,可以使用Controller的TryUpdateModel()方法. [HttpPost] public ActionResul ...
- stl binary search
stl binary search */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola,&q ...
- RHEL7 -- Linux搭建FTP虚拟用户
安装vsftpd软件包[root@localhost ~]# yum install vsftpd -y [root@localhost ~]# yum install db4 db4-utils 建 ...
- iPhone/Mac Objective-C内存管理教程和原理剖析
http://www.cocoachina.com/bbs/read.php?tid-15963.html 版权声明 此文版权归作者Vince Yuan (vince.yuan#gmail.com)所 ...
- 问题-[Delphi]SendMessageTimeout调用后卡住点击任务栏还会出现窗体处理
问题现象:在使用SendMessageTimeout函数后,5秒后WIN把进程挂在起.这时把程序最小化(原因就是不想让用户看到卡的界面),但点击任务栏按钮界面还原了,拦截消息失败(原因是挂起后消息都放 ...
- SDWebImage原理小结
先贴上github上的地址:https://github.com/rs/SDWebImage,至于安装方式这里就不多说了,它的框架说明中都有,不过建议使用cocoaPod来安装比较好,方便日后的维护代 ...
- java小算法—大衍数列
题目: 中国古代文献中,曾记载过“大衍数列”, 主要用于解释中国传统文化中的太极衍生原理. 它的前几项是:0.2.4.8.12.18.24.32.40.50 ... 其规律是:对偶数项,是序号平 ...