jjzjj

replacing

全部标签

javascript - 对象没有方法 'replace'

我尝试运行这个函数,它将所有选中的复选框值抓取到逗号分隔的字符串中,并将","转换为",",所以它读起来更好。问题是我遇到了一个奇怪的错误:$('.name_boxes').live('click',function(){varall_boxes=$('.name_boxes');varall_boxes_values=[]for(vari=0;i控制台错误说:UncaughtTypeError:ObjectAaronRamsey,AaronRenfreehasnomethod'replace'.我没有收到警告框。这有点超出我的理解范围,有人可以解释我做错了什么吗?

javascript - string.replace 在 node.js Express 服务器中不起作用

我需要读取一个文件并用动态内容替换该文件中的一些文本。当我尝试string.replace时,它​​不适用于我从文件中读取的数据。但对于它正在工作的字符串。我是使用node.js和express。fs.readFile('test.html',functionread(err,data){if(err){console.log(err);}else{varmsg=data.toString();msg.replace("%name%","myname");msg.replace(/%email%/gi,'example@gmail.com');temp="Hello%NAME%,wou

Javascript - string.replace() 文本跨越多行?

假设我有文本(不是html),我是从文本区域中提取的。看起来像:ALTERLOGIN[user1]DISABLEGO~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~ALTERLOGIN[user2]DISABLEGO~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importa

javascript - String.prototype.replace() 删除破折号和下划线

我正在尝试使用String.prototype.replace()删除字符串中出现的所有破折号和下划线,但它不起作用,我也不知道为什么。我的代码:varstr="dash-and_underscore";str=str.replace(/_|\-/,"");console.log(str);输出:"dashand_underscore"在Chrome控制台中。由于|的行为类似于OR运算符,我做错了什么?我试过解决方案here,但它没有用,或者我太笨了,无法理解-这是一个选项;) 最佳答案 试试这个:str=str.replace(/

javascript - 在 replace() 中调用 ajax 函数

我有一个包含ajax调用的函数:functionexample(param,callback){$.ajax({type:"GET",url:param,contentType:"application/json;charset=utf-8",dataType:"jsonp",success:function(data){//dosomethingwithdatacallback(data);}});}我这样调用它:example("http://www.example.com",function(result){//dosomethingwithresult})但是,我想在这种情况下

javascript - Chrome 浏览器中奇怪的 .replace() 行为

saadad$(".allownumericwithdecimal").live("keypresskeyup",function(event){$(this).val($(this).val().replace(/[^0-9\.]/g,''));vartext=$(this).val();if(!((event.which>=48&&event.which2)){//event.preventDefault();}}vartext=$(this).val();if((event.which>=48&&event.which2){//event.preventDefault();}if

JavaScript replace() 方法美元符号

我有一个像aman/gupta这样的字符串,我想将它替换为aman$$gupta,为此我正在使用JavaScriptreplace方法如下:leta="aman/gupta"a=a.replace("/","$")console.log(a)//'aman$gupta'a="aman/gupta"a=a.replace("/","$$")console.log(a)//'aman$gupta'a="aman/gupta"a=a.replace("/","$$$")console.log(a)//'aman$$gupta'为什么第一种情况和第二种情况相同,而当我使用$$$而不是$$时却得

javascript - 使用 JavaScript 的 replace() 方法对变量进行全局切换

在我无法弄清楚它如何单独工作之后,我无法举出任何例子。我想要做的就是获取一个已分配给一个值的字符串,并将其用作所有匹配项的替换匹配字符串。varreplacement='i';vartext='tieiam';text=text.replace(replacement,'');//'teiam'text=text.replace(/tieiam/g,'');//'team'如何一起使用它们? 最佳答案 你想要的是使用RegExp对象:text=text.replace(newRegExp(replacement,'g'),'');S

javascript - val.replace(/[^a-zA-Z_-0-9]/g, '' ) 产生 SyntaxError : invalid range in character class

我需要替换所有与a-zA-Z_-0-9范围不匹配的字符。所以我做了val.replace(/[^a-zA-Z_-0-9]/g,'')但得到了错误。我怎么能咬这个?谢谢 最佳答案 如果要在字符类中包含减号“-”,则必须将其放在范围末尾:val.replace(/[^a-zA-Z_0-9-]/g,'') 关于javascript-val.replace(/[^a-zA-Z_-0-9]/g,'')产生SyntaxError:invalidrangeincharacterclass,我们在Sta

javascript - 拖动 : Replacement of the data

我得到了一个包含一些html元素的网页,其中包括一个文本区域和一个嵌入式contenteditableiframe(一个rte)。使用这段代码,我设法在主页上捕获拖动手势事件并设置文本/html数据jQuery(document).bind('draggesture',function(event){event.originalEvent.dataTransfer.setData('text/html','my_data');});现在,当拖放到主页上的文本区域时,“my_data”会被丢弃。放入contenteditableiframe也会掉落“my_data”。但是我在这里遇到了三