阅读背景:

Uncaught TypeError: Cannot call method 'replace' of undefined 的解决

来源:互联网 
 
Uncaught TypeError: Cannot call method 'replace' of undefined 的解决

1. js代码
	var rip = $("#RSIP").val(); 
	rip = rip.replace(/\r|\n/g,":");

	报错 Uncaught TypeError: Cannot call method 'replace' of undefined
2. 代码更改为
	var rip = $("#RSIP").val();
	console.log(rip)
	rip = rip.replace(/\r|\n/g,":");
	得到输出为
	Undefined editTask:28
	Uncaught TypeError: Cannot call method 'replace' of undefined 
3.可见 rip为未定义,在html中搜 RSIP,发现
	<textarea name='RSIP'  class="xxlarge" style="width:  210px; height: 60px;" disabled="disabled">{$pe.orderData.RSIP}</textarea>   
	可见的确未定义  
4.更改为

	<textarea name='RSIP' id='RSIP'  class="xxlarge" style="width:  210px; height: 60px;" disabled="disabled">{$pe.orderData.RSIP}</textarea>   
	之后,代码正常

	也可将js代码修改为
	var rip = $("textarea[name='RSIP']").val();
	去取得对应的元素数据
5.结论:发现难以判断的错误时,多使用 console.log Uncaught TypeError: Cannot call method 'rep



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: