Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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将加载的url替换为另一个url_Javascript_Jquery - Fatal编程技术网

Javascript 通过jquery将加载的url替换为另一个url

Javascript 通过jquery将加载的url替换为另一个url,javascript,jquery,Javascript,Jquery,我不是Javascript的金星奖章,所以请容忍我 我们在站点上添加了一个通过javascript(称为ratecard)从外部加载的链接,但是该项目所用于的链接不正确,因此使用一点javascript/jquery,我们试图覆盖它 加载插件时,它会添加到预定义的div a location.href。我试图通过下面的javascript来覆盖它 这是正在生成的div <div class="wdgt_widget" style="border:1px solid #1d8be0 !imp

我不是Javascript的金星奖章,所以请容忍我

我们在站点上添加了一个通过javascript(称为ratecard)从外部加载的链接,但是该项目所用于的链接不正确,因此使用一点javascript/jquery,我们试图覆盖它

加载插件时,它会添加到预定义的div a location.href。我试图通过下面的javascript来覆盖它

这是正在生成的div

<div class="wdgt_widget" style="border:1px solid #1d8be0 !important; border-radius:8px  !important; padding:11px  !important; width:300px !important; height:64px  !important; cursor:pointer  !important; box-sizing: border-box  !important;" onclick="location.href='https://ratecard.io/staffing-ms'"></div>

因此,我试图首先解除单击操作的绑定并添加一个新的,但什么也没有发生。请参阅下面的脚本

        <script>
            jQuery(document).ready(function ($) {
                setTimeout(function() {
                    $('#wdgt_widget').unbind();
                    $('#wdgt_widget').attr('click' 'location.href="https://ratecard.io/staffing-ms/review/");
                }, 5000);   
            });
        </script>

jQuery(文档).ready(函数($){
setTimeout(函数(){
$(“#wdgt_小部件”).unbind();
$('#wdgt_widget').attr('单击''位置。href='https://ratecard.io/staffing-ms/review/");
}, 5000);   
});
我在上面添加了一个5秒的计时器,因为我想确保代码将被加载并且已经生成了div


可悲的是什么也没发生。是否可以简单地在onclick上使用replace?还是我在这里做错了什么?

你应该使用
.wdgt\u widget
而不是
\wdgt\u widget
。因为你的部门没有身份证

<div class="wdgt_widget" style="border:1px solid #1d8be0 !important; border-radius:8px  !important; padding:11px  !important; width:300px !important; height:64px  !important; cursor:pointer  !important; box-sizing: border-box  !important;" onclick="location.href='https://ratecard.io/staffing-ms'"></div>

<script>
            jQuery(document).ready(function ($) {
                setTimeout(function() {
                    $('.wdgt_widget').unbind();
                    $('.wdgt_widget').attr('click' 'location.href="https://ratecard.io/staffing-ms/review/");
                }, 5000);   
            });
        </script>

jQuery(文档).ready(函数($){
setTimeout(函数(){
$('.wdgt_小部件').unbind();
$('.wdgt_小部件').attr('单击''位置。href='https://ratecard.io/staffing-ms/review/");
}, 5000);   
});

您应该使用
.wdgt\u小部件
而不是
\wdgt\u小部件
。因为你的部门没有身份证

<div class="wdgt_widget" style="border:1px solid #1d8be0 !important; border-radius:8px  !important; padding:11px  !important; width:300px !important; height:64px  !important; cursor:pointer  !important; box-sizing: border-box  !important;" onclick="location.href='https://ratecard.io/staffing-ms'"></div>

<script>
            jQuery(document).ready(function ($) {
                setTimeout(function() {
                    $('.wdgt_widget').unbind();
                    $('.wdgt_widget').attr('click' 'location.href="https://ratecard.io/staffing-ms/review/");
                }, 5000);   
            });
        </script>

jQuery(文档).ready(函数($){
setTimeout(函数(){
$('.wdgt_小部件').unbind();
$('.wdgt_小部件').attr('单击''位置。href='https://ratecard.io/staffing-ms/review/");
}, 5000);   
});
您应该这样做:

$(document).ready(function () {
    setTimeout(function() {
        $('.wdgt_widget')
          .unbind()
          .attr('onclick', 'location.href="https://ratecard.io/staffing-ms/review/"');
    }, 5000);   
});
您应该这样做:

$(document).ready(function () {
    setTimeout(function() {
        $('.wdgt_widget')
          .unbind()
          .attr('onclick', 'location.href="https://ratecard.io/staffing-ms/review/"');
    }, 5000);   
});
问题: 1) 此
$(“#wdgt_小部件”)
您正在用于按id选择的选择器中使用
。但是您的
div
中有一个类,因此请使用

解决方案:1)使用此
$('.wdgt\u小部件')


问题:2)attr函数末尾缺少一个
,在
单击
位置之间也有一个

$('#wdgt_小部件').attr('单击''位置。href='https://ratecard.io/staffing-ms/review/"); // , 和“丢失”。

解决方案:2)更改
.attr('click''位置。href='https://ratecard.io/staffing-ms/review/“”
.attr('click','location.href=”https://ratecard.io/staffing-ms/review/“)
注:我在中间添加了一个
,并在末尾添加了

问题: 1) 此
$(“#wdgt_小部件”)
您正在用于按id选择的选择器中使用
。但是您的
div
中有一个类,因此请使用

解决方案:1)使用此
$('.wdgt\u小部件')


问题:2)attr函数末尾缺少一个
,在
单击
位置之间也有一个

$('#wdgt_小部件').attr('单击''位置。href='https://ratecard.io/staffing-ms/review/"); // , 和“丢失”。

解决方案:2)更改
.attr('click''位置。href='https://ratecard.io/staffing-ms/review/“”
.attr('click','location.href=”https://ratecard.io/staffing-ms/review/“)

注意:我在中间添加了一个
,并在末尾添加了

您应该使用
.wdgt\u小部件
,而不是
\wdgt\u小部件
。我想是吧。由于您的
div
没有id,并且属性名称是
onclick
not
单击
,并且
unbind()
不会解除绑定内联脚本。您发布的代码中存在synthax错误…您应该使用
.wdgt\u小部件
而不是
\wdgt\u小部件
。我想是吧。由于您的
div
没有id,并且属性名称是
onclick
not
单击
,并且
unbind()
不会解除绑定内联脚本。你发布的代码中有synthax错误…正是我想要的。我意识到,当我发布这篇文章时,我的班级和我的身份混淆了。。。但最后的命令和引语帮了我。Awesome@Dorvalla很高兴我能帮上忙。这正是我要找的。我意识到,当我发布这篇文章时,我的班级和我的身份混淆了。。。但最后的命令和引语帮了我。Awesome@Dorvalla很高兴我能帮忙。