js报错 replaceAll is not a function

牛客网用JavaScript V8,发现没有replaceAll的方法,replace只能替换第一个遍历到的元素,换个方式实现替换所有的效果

n=n.replace(new RegExp(arr[i],'g'),'');

把n里面的arr[i]的字符替换成空

2023年3月16日更新更加简单的方法,如果知道具体的替换字符,比如kang替换成空,就按如下写,如果未知的,或者是个变量,就按如上写。

n=n.replace(/kang/g,'');
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery Version 1.5 API 中文版 IE用户无法在线查看本文档,请下载jQuery API Version1.5 中文版AIR客户端查看,或者使用chrome,safari,firefox,opera等浏览器查看!!! jQuery 1.5 API Cheat Sheet来源 Selectors Basics #id element .class, .class.class * selector1, selector2 Hierarchy ancestor descendant parent > child prev + next prev ~ siblings Basic Filters :first :last :not(selector) :even :odd :eq(index) :gt(index) :lt(index) :header :animated Content Filters :contains(text) :empty :has(selector) :parent Visibility Filters :hidden :visible Child Filters :nth-child(expr) :first-child :last-child :only-child Attribute Filters [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [attribute|=value] [attribute~=value] [attribute][attribute2] Forms :input :text :password :radio :checkbox :submit :image :reset :button :file Form Filters :enabled :disabled :checked :selected Core jQuery function $.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( ) $.jQuery( html [, ownerDocument] ), .jQuery( html, props ) $.jQuery( fn ) jQuery Object Accessors $.each( fn(index, element) ) num.size( ) , .length str.selector el.context $.eq( index ) jQuery.error( str ) [el],el.get( [index] ) num.index( ).index( selector ).index( element ) $jQuery.pushStack( elements, [name, arguments] ) arr.toArray( ) Interoperability $jQuery.noConflict( [extreme] ) ver. 04-02-2011 Attributes Attributes str.attr( name ) $.attr( name, val ), .attr( map ), .attr( name, fn(index, attr) ) $.removeAttr( name ) Class $.addClass( class ), .addClass( fn(index, class) ) bool.hasClass( class ) $.removeClass( [class] ), .removeClass( fn(index, class) ) $.toggleClass( class [, switch] ), .toggleClass( fn(index, class) [, switch] ) HTML, text str.html( ) $.html( val ), .html( fn(index, html) ) str.text( ) $.text( val ), .text( fn(index, html) ) Value str,arr.val( ) $.val( val ), .val( fn() ) CSS CSS str.css( name ) $.css( name, val ), .css( map ), .css( name, fn(index, val) ) Positioning obj.offset( ) $.offset( coord ), .offset( fn( index, coord ) ) $.offsetParent( ) obj.position( ) int.scrollTop( ) $.scrollTop( val ) int.scrollLeft( ) $.scrollLeft( val ) Height and Width int.height( ) $.height( val ), .height( fn(index, height ) ) int.width( ) $.width( val ), .width(( fn(index, height ) ) int.innerHeight( ) int.innerWidth( ) int.outerHeight( [margin] ) int.outerWidth( [margin] ) Deferred deferred object = { defdone(doneCallbacks) deffail(failCallbacks) boolisRejected() boolisResolved() defreject([args]) defrejectWith(context, [args]) defresolve([args]) defresolveWith(context, [args]) defthen(doneCallbacks, failCallbacks) }1.5+ def.when(deferreds)1.5+ Traversing Filtering $.eq( index ) $.first( ) $.last( ) $.has( selector ), .has( element ) $.filter( selector ), .filter( fn(index) ) bool.is( selector ) $.map( fn(index, element) ) $.not( selector ), .not( elements ), .not( fn( index ) ) $.slice( start [, end] ) Tree traversal $.children( [selector] ) $.closest( selector [, context] ) arr.closest( selectors [, context] ) $.find( selector ) $.next( [selector] ) $.nextAll( [selector] ) $.nextUntil( [selector] ) $.offsetParent( ) $.parent( [selector] ) $.parents( [selector] ) $.parentsUntil( [selector] ) $.prev( [selector] ) $.prevAll( [selector] ) $.prevUntil( [selector] ) $.siblings( [selector] ) Miscellaneous $.add( selector [, context] ), .add( elements ), .add( html ) $.andSelf( ) $.contents( ) $.end( ) Manipulation Inserting Inside $.append( content ), .append( fn( index, html ) ) $.appendTo( target ) $.prepend( content ), .prepend( fn( index, html ) ) $.prependTo( target ) Inserting Outside $.after( content ), .after( fn() ) $.before( content ), .before( fn() ) $.insertAfter( target ) $.insertBefore( target ) Inserting Around $.unwrap( ) $.wrap( wrappingElement ), .wrap( fn ) $.wrapAll(wrappingElement ), .wrapAll( fn ) $.wrapInner( wrappingElement ), .wrapInner( fn ) Replacing $.replaceWith( content ), .replaceWith( fn ) $.replaceAll( selector ) Removing $.detach( [selector] ) $.empty( ) $.remove( [selector] ) Copying $.clone( [withDataAndEvents], [deepWithDataAndEvents] )1.5∗ Events Page Load $.ready( fn() ) Event Handling $.bind( type [, data ], fn(eventObj) ) $.bind( type [, data], false ) $.bind( array ) $.unbind( [type] [, fn]) $.one( type [, data ], fn(eventObj) ) $.trigger( event [, data]) obj.triggerHandler( event [, data]) $.delegate( selector, type, [data], handler) $.undelegate( [selector, type, [handler]]) Live Events $.live( eventType [, data], fn() ) $.die( ), .die( [eventType] [, fn() ]) Interaction Helpers $.hover( fnIn(eventObj), fnOut(eventObj)) $.toggle( fn(eventObj), fn2(eventObj) [, ...]) Event Helpers function ( [data,] [fn] ) $.blur,.mousedown,.change,.mouseenter,.click,.mouseleave,.dblclick,.mousemove,.error,.mouseout,.focus,.mouseover,.focusin,.mouseup,.focusout,.resize,.keydown,.scroll,.keypress,.select,.keyup,.submit,.load( [data,] fn ),.unload( [data,] fn ) Event object event = { elcurrentTarget, *data, boolisDefaultPrevented(), boolisImmediatePropagationStopped(), boolisPropagationStopped(), strnamespace, numpageX, numpageY, preventDefault(), elrelatedTarget, objresult, stopImmediatePropagation(), stopPropagation(), eltarget, numtimeStamp, strtype, strwhich } Effects Basics $.show( [ duration [, easing] [, fn] ] ) $.hide( [ duration [, easing] [, fn] ] ) $.toggle( [showOrHide] ) $.toggle( duration [, easing] [, fn] ) Sliding $.slideDown( duration [, easing] [, fn] ) $.slideUp( duration [, easing] [, fn] ) $.slideToggle( [duration] [, easing] [, fn] ) Fading $.fadeIn( duration [, easing] [, fn] ) $.fadeOut( duration [, easing] [, fn] ) $.fadeTo( [duration,] opacity [, easing] [, fn] ) $.fadeToggle( [duration,] [, easing] [, fn] ) Custom $.animate( params [, duration] [, easing] [, fn] ) $.animate( params, options ) $.stop( [clearQueue] [, jumpToEnd] ) $.delay( duration [, queueName] ) Settings booljQuery.fx.off numjQuery.fx.interval AJAX Low-Level Interface jqXHRjQuery.ajax( options, [settings] )1.5+ mapaccepts boolasync = true fnbeforeSend( jqXHR, config) boolcache = true fncomplete( jqXHR, status) mapcontents strcontentType objcontext mapconverters boolcrossDomain obj, strdata fndataFilter( data, type ) boolglobal = true mapheaders boolifModified = false strjsonp fnjsonpCallback strpassword boolprocessData = true strscriptCharset mapstatusCode numtimeout booltraditional strtype = 'GET' strurl = curr. page strusername fnxhr strdataType ∈ {xml, json, script, html} fnerror( jqXHR, status, errorThrown ) fnsuccess( data, status, jqXHR ) jQuery.ajaxSetup( options ) Shorthand Methods $.load( url [, data] [, fn( responseText, status, XHR )] ) jqXHRjQuery.get( url [, data] [, fn( data, status, XHR )] [, type] ) jqXHRjQuery.getJSON( url [, data] [, fn( data, status )] ) jqXHRjQuery.getScript( url [, fn( data, status )] ) jqXHRjQuery.post( url [, data] [, fn( data, status )] [, type] ) Global Ajax Event Handlers $.ajaxComplete( fn( event, XHR, options ) ) $.ajaxError( fn( event, XHR, options, thrownError ) ) $.ajaxSend( fn( event, XHR, options ) ) $.ajaxStart( fn( ) ) $.ajaxStop( fn( ) ) $.ajaxSuccess( fn(event, XHR, options) ) Miscellaneous str.serialize( ) [obj].serializeArray( ) strjQuery.param( obj, [traditional] ) Utilities Browser and Feature Detection objjQuery.support objjQuery.browserdeprecated strjQuery.browser.versiondeprecated booljQuery.boxModeldeprecated Basic operations objjQuery.each( obj, fn( index, valueOfElement ) ) objjQuery.extend( [deep,] target, obj1 [, objN] ) arrjQuery.grep( array, fn( element, index ) [, invert] ) arrjQuery.makeArray( obj ) arrjQuery.map( array, fn( element, index ) ) numjQuery.inArray( val, array ) arrjQuery.merge( first, second ) fnjQuery.noop fnjQuery.proxy( fn, scope ), jQuery.proxy( scope, name ) fnjQuery.sub( )1.5+ arrjQuery.unique( array ) strjQuery.trim( str ) objjQuery.parseJSON( str ) Data functions $.clearQueue( [name] ) $.dequeue( [name] ), jQuery.dequeue( [name] ) objjQuery.data( element, key ), jQuery.data( ) obj.data( ), .data( key ) $.data( key, val ), .data( obj ) $.removeData( [name] ) [fn].queue( [name] ) jQuery.queue( [name] ) $.queue( [name,] fn( next ) ), jQuery.queue( [name,] fn( ) ) $.queue( [name,] queue ), jQuery.queue( [name,] queue ) Test operations strjQuery.type( obj ) booljQuery.isArray( obj ) booljQuery.isEmptyObject( obj ) booljQuery.isFunction( obj ) booljQuery.isPlainObject( obj ) booljQuery.isWindow( obj ) 获取jQuery 1.5 API文档
引用\[1\]:replaceAll是一个字符串的方法,用于替换字符串中的所有匹配项。然而,它在某些浏览器版本中可能不被支持。引用\[2\]中提到,Chrome浏览器仅在版本85以上支持replaceAll方法。所以,如果你在低于85版本的Chrome浏览器中使用replaceAll方法,就会报错"replaceAll is not a function"。为了解决这个问题,你可以使用其他方法来替换字符串中的所有匹配项。例如,你可以使用split和join方法,或者使用正则表达式的replace方法。引用\[2\]中给出了两个解决方法。第一个方法是使用split和join方法,将字符串分割成数组,然后用指定的替换字符连接数组元素。第二个方法是使用正则表达式的replace方法,通过指定全局匹配标志"g"来替换所有匹配项。另外,你也可以考虑升级你的浏览器版本以支持replaceAll方法。\[2\] #### 引用[.reference_title] - *1* [解决replaceAll报错:string.replaceAll is not a function](https://blog.csdn.net/qq_34626094/article/details/128672647)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [巧遇replaceAll报错:string.replaceAll is not a function](https://blog.csdn.net/weixin_49985592/article/details/127100456)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [replaceAll is not a function 问题解决](https://blog.csdn.net/weixin_44921956/article/details/126245067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值