简体   繁体   English

在asp.net上的简单jQuery不适用于firefox

[英]simple jquery on asp.net does not work on firefox

I have been struggling with getting this work on Firefox. 我一直在努力在Firefox上进行这项工作。 Hope there is somebody help me! 希望有人帮我!

Basically; 基本上; Firefox ignores the button click function and it's sub functions and the button posts the page instead of running the jquery code. Firefox忽略按钮单击功能及其子功能,并且按钮发布页面而不运行jquery代码。

It works on IE and Chrome but not on Firefox. 它适用于IE和Chrome,但不适用于Firefox。

Thank you for your help in advance. 提前谢谢你的帮助。

Here is the output code: 这是输出代码:

<script type="text/javascript" language="javascript">
    $(document).ready(function() {

        $(".CatList li").click(function() {
            if ($(this).is(".selected")) {
                $(this).attr("class", "");
                $('#ctl00_ContentPlaceHolderRight_CatChanged').val(1);
                return false;
            }
            else {
                $(this).attr("class", "selected");
                $('#ctl00_ContentPlaceHolderRight_CatChanged').val(1);
                return false;
            }

        });


        $("#ctl00_ContentPlaceHolderRight_btnSave").click(function() {
            var elements = $("li.selected");
            if (elements.val() == null) {
                alert("You must select at least one category");
                return false;
            }
            else {
                elements.each(function() {
                    $('#ctl00_ContentPlaceHolderRight_CatChecked').val($('#ctl00_ContentPlaceHolderRight_CatChecked').val() + "," + $(this).attr("id"));
                    return true;
                });
            }
        });
    });
</script>

Do you know firebug Firefox Extension? 您知道萤火虫Firefox扩展程序吗? It is very useful for debug Javascript on Firefox. 这对于在Firefox上调试Java脚本非常有用。

Firebug also include a Javascript console where you can test your functions. Firebug还包括一个Javascript控制台,您可以在其中测试功能。

Don't check against null -- try to stick with the undefined that jQuery ensures. 不要检查null尝试坚持使用jQuery确保的undefined Check what elements.val() returns to start (just alert it). 检查哪些elements.val()返回以开始(只是alert它)。

Also, you don't preventDefault() or return false in the else clause which could be a reason for Firefox to submit the page. 另外,您也不要preventDefault()或在else子句中return false ,这可能是Firefox提交页面的原因。

Thank you tjko, using alert saved my day. 谢谢tjko,使用警报救了我的一天。 I was just too confused. 我太困惑了。 I have changed the code as below and everything works perfectly: 我更改了如下代码,一切正常:

            var elements = $("li.selected");
            elements.each(function() {
                $('#<%=CatChecked.ClientID%>').val($('#<%=CatChecked.ClientID%>').val() + "," + $(this).attr("id"));
            });
            if ($('#<%=CatChecked.ClientID%>').val() == "") {
                alert("You must select at least one category");
                return false;
            }
            else {
                //alert($('#<%=CatChecked.ClientID%>').val());
                return true;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM