[英]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.