Answers:
val()
不返回jQuery对象,因此无法进行链接。您正在trim()
字符串上调用该方法,但IE尚不了解String.trim
。
另一个选择是直接定义方法String
,以防丢失:
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
//Your implementation here. Might be worth looking at perf comparison at
//http://blog.stevenlevithan.com/archives/faster-trim-javascript
//
//The most common one is perhaps this:
return this.replace(/^\s+|\s+$/g, '');
}
}
然后trim
无论浏览器如何都可以工作:
var result = " trim me ".trim();