jQuery更改href [英] Jquery to change href

查看:115
本文介绍了jQuery更改href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当浏览器宽度低于767px时,我已经成功地使用了一些JavaScript来更改a href.在不同的站点上使用相同的代码,弹出侧面的链接在767px以上不起作用,但会重定向到767px以下的正确页面. 请您帮我做些更改,以便锚点打开侧面弹出框可以在767px以上起作用.

I have successfully used some javascript to change the a href when the browser width goes below 767px. Using the same code on a different site the link for the side pop out does not work above 767px but does redirect to the correct page below 767px. Please can you help me make the changes so that the anchor to open the side pop out works above 767px.

站点: http://signfit.multi-web-services.co.uk/

jQuery:

jQuery(document).ready(function() {
    jQuery('.pwebcontact229_toggler').off().click(function (e) {
        e.preventDefault();

        if (jQuery(window).width() < 767) {
            window.location = '/contact-us';
        } else {
            pwebContact229.toggleForm();
        }
    });
});

推荐答案

问题在于事件触发得太早了,并且更改了文档以准备加载到窗口中似乎已经解决了我的问题.

The problem was that the event as being fired too early and changing document ready to window load seems to have fixed my issue.

因为我是JavaScript新手,所以不知道这是否正确;似乎为我工作了!

Don't know if this is the correct way as I am an JavaScript novice; seems to have worked for me though!

这篇关于jQuery更改href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆