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 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值