简体   繁体   English

为什么我收到错误“Uncaught TypeError: st.replace is not a function”

[英]Why am I getting the error "Uncaught TypeError: st.replace is not a function"

I trying to build a portfolio.我试图建立一个投资组合。 I am not a javascript expert and am not sure what to remove, or what is at fault.我不是 javascript 专家,不确定要删除什么,或者有什么问题。 The page works fine but as soon as I try to go to the homepage the exit is very slow and the console throws an error.该页面工作正常,但是一旦我尝试转到主页,退出速度非常慢,并且控制台会引发错误。

"Uncaught TypeError: st.replace is not a function" “未捕获的类型错误:st.replace 不是函数”

This snippet below is the piece that is faulty and gives me the error as soon as I click the home button to navigate away from the 'services' page.下面的这个片段是有问题的部分,一旦我单击主页按钮导航离开“服务”页面,就会出现错误。

Any instructions to as what is incorrect in the snippet are appreciated, thank you.感谢您对代码片段中不正确内容的任何说明,谢谢。

            htmlDoc: function(st) {
                var n, i = e(),
                    r = /<(\/?)(html|head|body|title|base|meta)(\s+[^>]*)?>/gi,
                    o = "ss" + Math.round(1e5 * Math.random()),
                    a = st.replace(r, function(t, n, r, a) {
                        var s = {};
                        return n || (e.merge(i, e("<" + r + "/>")), a && e.each(e("<div" + a + "/>")[0].attributes, function(e, t) {
                            s[t.name] = t.value
                        }), i.eq(-1).attr(s)), "<" + n + "div" + (n ? "" : ' id="' + o + (i.length - 1) + '"') + ">"
                    });
                return i.length ? (n || (n = e("<div/>")), n.html(a), e.each(i, function(e) {
                    var t = n.find("#" + o + e).before(i[e]);
                    i.eq(e).html(t.contents()), t.remove()
                }), n.children().unwrap()) : e(t)
            },

EDIT FelixKling编辑 FelixKling

Thanks, @FelixKling Is seems to have several values:谢谢,@FelixKling 似乎有几个值:

"st = /-([\\da-z])/gi," "st = /-([\\da-z])/gi,"

and

" st = ":(" + rt + ")(?:((('((?:\\\\.|[^\\\\']) )'|\\"((?:\\\\.|[^\\\\\\"]) )\\")|((?:\\\\.|[^\\()[]]|" + at + ") )|. ))|)", " " st = ":(" + rt + ")(?:((('((?:\\\\.|[^\\\\']) )'|\\"((?:\\\\.|[^\\ \\\\"]) )\\")|((?:\\\\.|[^\\()[]]|" + at + ") )|. ))|)", "

and

" St = ["Top", "Right", "Bottom", "Left"], " " St = ["顶部", "右侧", "底部", "左侧"], "

but the last one has a Capital letter S. Please copy paste this answer to read it more cleartly.但最后一个有大写字母S。请复制粘贴此答案以更清楚地阅读。 If i need to explain some more please let me know.如果我需要解释更多,请告诉我。

Your issue seems to be that st is not a string.您的问题似乎是st不是字符串。 Add a verification line to the top of the function that makes sure the argument is of the type expected.在函数顶部添加验证行,以确保参数为预期类型。

if (typeof st !== 'string') {
    // HANDLE IT HERE (throw an error, return false/null, whatever you need
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会出现“未捕获的TypeError”错误? - Why am I getting 'Uncaught TypeError' error? 我为什么会收到“ Uncaught TypeError:下载不是函数” - Why am I getting “Uncaught TypeError: download is not a function” 为什么会出现“未捕获的TypeError:getEnumerator不是函数”? - Why am I getting, “Uncaught TypeError: getEnumerator is not a function”? 为什么我会收到这个错误:Uncaught TypeError: this.createLink is not a function at new Link at<anonymous> 1:9? - Why am I getting this error: Uncaught TypeError: this.createLink is not a function at new Link at <anonymous>1:9? 为什么我收到错误类型错误:“xyz”不是 function? - Why am I getting ERROR TypeError: “xyz” is not a function? 为什么在另一个 function 中使用时会出现“未捕获的类型错误:regex.test 不是函数”? - Why am I getting 'Uncaught TypeError: regex.test is not a function' when used inside another function? 当我将函数传递给React.js的子组件时,为什么会出现未捕获的TypeError? - Why am I getting an uncaught TypeError when I pass a function to a child component in React.js? 我为什么会收到错误:Uncaught TypeError:无法读取未定义的属性“ left” - Why am I getting the error: Uncaught TypeError: Cannot read property 'left' of undefined Backbone.js 视图是否需要 jQuery 或 Zepto? (或者:为什么我会收到“未捕获的类型错误:未定义不是函数”?) - Do Backbone.js views require jQuery or Zepto? (Or: why am I getting “Uncaught TypeError: undefined is not a function”?) 我收到此错误 Uncaught TypeError: notes.map is not a function in my app - I am getting this error Uncaught TypeError: notes.map is not a function in my app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM