объединение двух функций jquery для использования на одной HTML-странице - PullRequest
0 голосов
/ 18 ноября 2011

Как я могу объединить эти две функции jQuery?или .js.Попытка соединить их на одной странице приводит к тому, что последние вообще не работают.

Они отлично работают для своей работы, если я использую только один на странице, но мне нужны оба.

Первое, что у меня есть:

(function ($) {
    $(document).ready(function () {
        // Dropdown Menu
        if (!($.browser.msie && ($.browser.version == 6))) {
            $("ul#topnav li:has(ul)").addClass("dropdown");
        }
        $("ul#topnav li.dropdown").hover(function () {
            $('ul:first', this).css({
                visibility: "visible",
                display: "none"
            }).slideDown('normal');
        }, function () {
            $('ul:first', this).css({
                visibility: "hidden"
            });
        });
        $("div.prod_hold").hover(function () {
            $('.info', this).css({
                visibility: "visible",
                display: "none"
            }).slideDown('normal');
        }, function () {
            $('.info', this).css({
                visibility: "hidden"
            });
        });
        $("li.cat_hold").hover(function () {
            $('.info', this).fadeIn(300);
        }, function () {
            $('.info', this).fadeOut(200);
        });
        $("li.side_cart").hover(function () {
            $('#cart', this).fadeIn(500);
        }, function () {
            $('#cart', this).fadeOut(200);
        });
        $("li.side_currency").hover(function () {
            $('#currency', this).fadeIn(500);
        }, function () {
            $('#currency', this).fadeOut(200);
        });
        $("li.side_lang").hover(function () {
            $('#language', this).fadeIn(500);
        }, function () {
            $('#language', this).fadeOut(200);
        });
        $("li.side_search").hover(function () {
            $('#search', this).fadeIn(500);
        }, function () {
            $('#search', this).fadeOut(200);
        });
        $(".main_menu li").hover(function () {
            $('.secondary', this).fadeIn(500);
        }, function () {
            $('.secondary', this).fadeOut(200);
        });
        $(".cat_right ul li a").hover(function () {
            $(this).stop().animate({
                paddingLeft: 20,
                color: '#ccc'
            }, "fast")
        }, function () {
            $(this).stop().animate({
                paddingLeft: 10,
                color: '#999'
            }, "fast")
        });

        // Tipsy - tooltips jQuery plugin
        $('a.wish_button, a.compare_button, a#button-cart, a.twitter_follow').tipsy({
            gravity: 's',
            fade: true,
            title: function () {
                return this.getAttribute('original-title').toUpperCase();
            }
        });
        $('#service_links li a').tipsy({
            gravity: 'e',
            fade: true,
            title: function () {
                return this.getAttribute('original-title').toUpperCase();
            }
        });

        // SLIDING ELEMENTS
        $("ul.categories li, #sidebar ul.secondary_menu li").hover(function () {
            $("a", this).stop().animate({
                left: "15px"
            }, {
                queue: false,
                duration: 200
            });
        }, function () {
            $("a", this).stop().animate({
                left: "0px"
            }, {
                queue: false,
                duration: 200
            });
        });

        // FADING ELEMENTS
        $(".logo img, .oferta_s, .oferta_d").hover(function () {
            $(this).stop().animate({
                opacity: 0.6
            }, "medium")
        }, function () {
            $(this).stop().animate({
                opacity: 1
            }, "medium")
        });
        $(".intro").hover(function () {
            $(this).stop().animate({
                paddingBottom: 230
            }, "medium")
        }, function () {
            $(this).stop().animate({
                paddingBottom: 140
            }, "slow")
        });
        $(".desc_box,.desc_box2").hover(function () {
            $(".desc_box,.desc_box2").not(this).stop().animate({
                opacity: 0.7
            }, "fast")
        }, function () {
            $(".desc_box,.desc_box2").not(this).stop().animate({
                opacity: 1
            }, "fast")
        });
    });
})(window.jQuery);

// non jQuery scripts below
$(document).ready(function () {
    var interval;
    $('ul#myRoundabout').roundabout({
        'btnNext': '.next_round',
        'btnPrev': '.previous_round'
    }).hover(

    function () {
        clearInterval(interval);
    }, function () {
        interval = startAutoPlay();
    });
    interval = startAutoPlay();
});

function startAutoPlay() {
    return setInterval(function () {
        $('ul#myRoundabout').roundabout_animateToPreviousChild();
    }, 6000);
}

Когда я добавляю этот второй код, начинаются проблемы .. и код:

<!-- Validate email using regular expression -->

function validateEmail(emailValue) {
    var emailPattern = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
    return emailPattern.test(emailValue);
}
<!-- Validate Form fields -->

function validateForm() {
    var send_message = true;
    if (jQuery("textarea#message").val().length < 2) {
        jQuery("label#message_error").slideDown();
        jQuery("textarea#message").focus();
        send_message = false;
    }
    if (!validateEmail(jQuery("input#email").val())) {
        jQuery("label#email_error").slideDown();
        jQuery("input#email").focus();
        send_message = false;
    }
    if (jQuery("input#name").val().length < 2) {
        jQuery("label#name_error").slideDown();
        jQuery("input#name").focus();
        send_message = false;
    }
    return send_message;
}
jQuery(function () {
    <!-- Contact Form validation -->
    jQuery('.error').hide();
    jQuery("input#name").bind("keyup focusout", function () {
        if (jQuery(this).val().length > 1) {
            jQuery("label#name_error").slideUp();
        } else {
            jQuery("label#name_error").slideDown();
        }
    });
    jQuery("input#email").bind("keyup focusout", function () {
        if (validateEmail(jQuery(this).val())) {
            jQuery("label#email_error").slideUp();
        } else {
            jQuery("label#email_error").slideDown();
        }
    });
    jQuery("textarea#message").bind("keyup focusout", function () {
        if (jQuery(this).val().length > 1) {
            jQuery("label#message_error").slideUp();
        } else {
            jQuery("label#message_error").slideDown();
        }
    });
    <!-- Submitting Contact Form -->
    jQuery("form#contact_form").submit(function () {
        var dataString = jQuery(this).serialize();
        if (validateForm()) {
            jQuery.ajax({
                type: "POST",
                url: "FormToEmail.php",
                data: dataString,
                success: function () {
                    jQuery('#contact_form').slideUp('slow', function () {
                        jQuery(this).html("<div id='confirmation'></div>");
                        jQuery('#confirmation').html("<h4>Mesajul a fost trimis cu succes!</h4>").append("<p>Va multumim pentru ca ne-ati contactat. Va vom raspunde la e-mail in cel mai scurt timp posibil!</p>");
                        Cufon.refresh();
                        jQuery(this).slideDown('slow');
                    })
                }
            });
        }
        return false;
    });
})

1 Ответ

0 голосов
/ 19 ноября 2011

* РЕДАКТИРОВАТЬ *
Проблема была исправлена, это были комментарии.
Изменил <!-- comm --> на /* comm */, и он работает просто отлично.
Спасибо всем за ваше время и помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...