Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery。如果找不到,请更换链接_Javascript - Fatal编程技术网

Javascript Jquery。如果找不到,请更换链接

Javascript Jquery。如果找不到,请更换链接,javascript,Javascript,我是一个新手,我继承了一些讨厌的jquery代码。我正试图找到一种方法,这样,如果发现错误,它就会用另一个字符串替换该字符串。这是原始代码 W.load = function (b) { var c, d, g = W.prep; S = ! 0, Q = ! 1, O = x[P], b || _(a.extend(J, a.data(O, e))), ba(l), ba(h, J.onLoad), J.h = J.height? Z(J.height, "y") - M -

我是一个新手,我继承了一些讨厌的jquery代码。我正试图找到一种方法,这样,如果发现错误,它就会用另一个字符串替换该字符串。这是原始代码

    W.load = function (b) {
    var c, d, g = W.prep; S = ! 0, Q = ! 1, O = x[P], b || _(a.extend(J, a.data(O, e))), ba(l), ba(h, J.onLoad), J.h = J.height? Z(J.height, "y") - M - K: J.innerHeight && Z(J.innerHeight, "y"), J.w = J.width? Z(J.width, "x") - N - L: J.innerWidth && Z(J.innerWidth, "x"), J.mw = J.w, J.mh = J.h, J.maxWidth &&(J.mw = Z(J.maxWidth, "x") - N - L, J.mw = J.w && J.w < J.mw? J.w: J.mw), J.maxHeight &&(J.mh = Z(J.maxHeight, "y") - M - K, J.mh = J.h && J.h < J.mh? J.h: J.mh), c = J.href, V = setTimeout(function () {
        B.show()
    },
    100), J.inline?(Y().hide().insertBefore(a(c)[0]).one(l, function () {
        a(this).replaceWith(z.children())
    }), g(a(c))): J.iframe? g(" "): J.html? g(J.html): $(c)?(a(Q = new Image).addClass(f + "Photo").error(function () {
        //J.title = ! 1, g(Y("Error").text("This image could not be loaded"))
        J.title = ! 1, a(this).href.replace('http://www.old.com','http://www.new.com');
    }).load(function () {
        var a; Q.onload = null, J.scalePhotos &&(d = function () {
            Q.height -= Q.height * a, Q.width -= Q.width * a
        },
        J.mw && Q.width > J.mw &&(a =(Q.width - J.mw) / Q.width, d()), J.mh && Q.height > J.mh &&(a =(Q.height - J.mh) / Q.height, d())), J.h &&(Q.style.marginTop = Math.max(J.h - Q.height, 0) / 2 + "px"), x[1] &&(P < x.length - 1 || J.loop) &&(Q.style.cursor = "pointer", Q.onclick = function () {
            W.next()
        }), m &&(Q.style.msInterpolationMode = "bicubic"), setTimeout(function () {
            g(Q)
        },
但它不起作用。Ggr!任何帮助都将不胜感激。:)

更新*

上面的代码是我所在部门的完整代码

更新#2 这个答案有效,但我需要做

a(this).attr('src', function(i, current){ 
 if ( i === 'http://www.old.com'){
 return current.replace('http://www.old.com','http://www.new.com');
 }
 else if ( i === 'http://www.older.com'){
 return current.replace('http://www.older.com','http://www.new.com');
}
 else ();
 })

这不管用!!救命

您需要更换吗?如果您只想更改url,那么您可以这样做

J.title = ! 1, $(this).attr('href', 'http://new.com/*');

将当前url替换为给定的新url。

是否需要执行替换?如果您只想更改url,那么您可以这样做

J.title = ! 1, $(this).attr('href', 'http://new.com/*');
将当前url替换为给定的新url。

尝试

this.href.replace('http://old.com/' , 'http://new.com/');
如果要将当前元素上的实际属性更改为新属性,则

this.href = this.href.replace('http://old.com/' , 'http://new.com/');
如果您在引用
元素的处理程序中,则
引用该对象,您无需使用它创建jquery对象来访问其属性。。因此
this.href
将直接引用链接的
href
属性


免责声明:这是一个模糊/编码的脚本,您最好找到生成此脚本的原始脚本。。这个代码毫无意义,我们的建议是盲目的

从第一眼看,
这个
似乎是一个图像而不是一个链接,因此如果您想显示一个新图像,那么您需要更改
src
属性,而不是图像上不存在的
href

a(this).attr('src', function(i, current){ return current.replace('http://www.old.com','http://www.new.com');})
但是您还应该在其中执行
console.log(a.fn.jquery)
,以确保
a
是对
jquery

的引用

this.href.replace('http://old.com/' , 'http://new.com/');
如果要将当前元素上的实际属性更改为新属性,则

this.href = this.href.replace('http://old.com/' , 'http://new.com/');
如果您在引用
元素的处理程序中,则
引用该对象,您无需使用它创建jquery对象来访问其属性。。因此
this.href
将直接引用链接的
href
属性


免责声明:这是一个模糊/编码的脚本,您最好找到生成此脚本的原始脚本。。这个代码毫无意义,我们的建议是盲目的

从第一眼看,
这个
似乎是一个图像而不是一个链接,因此如果您想显示一个新图像,那么您需要更改
src
属性,而不是图像上不存在的
href

a(this).attr('src', function(i, current){ return current.replace('http://www.old.com','http://www.new.com');})

但是您还应该在其中执行
console.log(a.fn.jquery)
,以确保
a
是对
jquery

$(此)
返回jquery对象,
replace()
方法需要字符串;使用
$(this.text()
)或
$(this.html()
(或者如果它是
输入
元素,则可能使用
$(this.val()
)。但是没有加价,我不知道你在做什么。什么是
!1
for?我将尝试添加更具描述性的代码。但它的超级模糊的数学扔在乐趣。这个1表示如果获取图像的字符串返回0,则显示错误消息。太好了,嗯?
$(这个)
返回一个jQuery对象,
replace()
方法需要一个字符串;使用
$(this.text()
)或
$(this.html()
(或者如果它是
输入
元素,则可能使用
$(this.val()
)。但是没有加价,我不知道你在做什么。什么是
!1
for?我将尝试添加更具描述性的代码。但它的超级模糊的数学扔在乐趣。这个1表示如果获取图像的字符串返回0,则显示错误消息。太好了,嗯?我想下一个问题是$(这个)是链接元素吗?如果您使用console.log($(this));我添加了完整的代码部分,让您更好地了解我正在使用的代码,因此我想下一个问题是什么是$(这)它是链接元素吗?如果您使用console.log($(this));可能会有帮助我添加了完整的代码部分,让您更好地了解我的工作内容我添加了完整的代码部分,让您更好地了解我的工作内容with@user1937895,是否要在某处显示新的url?或者将href更改为现有链接?将href更改为现有链接link@user1937895,很乐意帮忙。。如果你觉得答案有用,你可以投票和/或接受。。请看,我已经添加了完整的代码部分,让您更好地了解我在做什么with@user1937895,是否要在某处显示新的url?或者将href更改为现有链接?将href更改为现有链接link@user1937895,很乐意帮忙。。如果你觉得答案有用,你可以投票和/或接受。。看见