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
(){
return
this
.replace(/(^\s*)|(\s*$)/g,
""
);}
var
test1 =
" 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
() {
var
str =
" 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 ...
随机推荐
- HDOJ -- 4699
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- $(function(){})里面不能声明定义函数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDOJ 1004题 Let the Balloon Rise strcmp()函数
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- RHEL7 -- Linux搭建FTP虚拟用户
安装vsftpd软件包[root@localhost ~]# yum install vsftpd -y [root@localhost ~]# yum install db4 db4-utils 建 ...
- opencv Installation in Linux and hello world
http://opencv.org/quickstart.html Installation in Linux These steps have been tested for Ubuntu 10.0 ...
- Tornado基本使用
一.快速上手 #!/usr/bin/env python # -*- coding:utf-8 -*- import tornado.ioloop import tornado.web class M ...
- 了解mongodb
本文大纲 基础了解mongodb(mongodb介绍,跟其他nosql区别,跟内存服务器区别等,使用场景) 在使用前,强力建议看哈http://wenku.baidu.com /link?url=lu ...
- asp.net mvc 提交model 接收不了
[HttpPost] //[ValidateInput(false)] public ActionResult AddNews1(_54Young_News_Model.m ...
- uva 1030 - Image Is Everything(迭代更新)
题目链接:uva 1030 - Image Is Everything 题目大意:有一个最大为n*n*n的立方体的一个不规整立体,由若干个1*1*1的小正方体构成(每一个小正方体被涂成不同的颜色),给 ...
- 报错:System.Data.Entity.Infrastructure.DbUpdateException 更新条目时出错
背景 往数据库添加数据,前端验证通过的情况下,提交报错,程序停在了SaveChanges()这行,并报如上错误. 分析 猜想是提交的领域模型不符合数据库要求,但不知道具体哪里出错.网上查资料,有人发现 ...