jQuery函数不适用于Second Time

时间:2014-01-23 10:26:39

标签: javascript jquery-ui jquery

我写这个jQuery之后它完全正常工作,第一次它给出了这个错误然后第二次没有功能工作。我也使用你可以在代码中看到的jQuery UI。

首次完成后会发生此错误:

  

未捕获的SyntaxError:意外的令牌} jquery-1.8.3.js:564

标记和代码:

<link href="../../StyleSheets/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script src="../../Scripts/jquery-1.8.3.js"></script>
<script src="../../Scripts/jquery-ui-1.9.2.custom.js"></script>
<script>
    $(function () {
        $(":checkbox").change(function () {
            var $this = $(this);
            if ($this.is(":checked")) {
                $this.closest("tr").addClass("SlectedtRow");
            } else {
                $this.closest("tr").removeClass("SlectedtRow");
            }
        })
        var tittle = '';
        var url = '';
        $("#dialog").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false,
            buttons: [
                {
                    text: "بلی",
                    click: function () {
                        DoAction();
                        $(this).dialog("close");
                    }
                },
                {
                    text: "خیر",
                    click: function () {
                        $(this).dialog("close");
                    }
                }
            ]
        });
        // Link to open the dialog
        $('#ConfirmRiver , #DeleteRiver').click(function (event) {

            var IsSelected = false;
            var ModalText = "  آیا رودخانه ";
            $('#RiverForm input:checked').each(function () {
                ModalText += this.value + " - "
                IsSelected = true;
            });

            if (IsSelected) {
                document.getElementById('ErrorContent').style.display = "none";
                ModalText = ModalText.slice(0, -2);
                if (this.id == 'DeleteRiver') {
                    ModalText += "حذف گردد" + "؟"
                    tittle = 'حذف رودخانه'
                    url = '@Url.Action("DeleteRiver", "WaterResourcesManagement")';
                }
                if (this.id == 'ConfirmRiver') {
                    ModalText += "تایید نهایی گردد" + "؟"
                    tittle = 'تایید اصلاح و بازبینی رودخانه '
                    url = '@Url.Action("ChangeRiverARStatus", "WaterResourcesManagement")';
                }
                $('#ModalMessgae').text(ModalText);
                $("#dialog").dialog("open");
                $("#dialog").dialog({ title: tittle });
                event.preventDefault();

            }
            else {
                document.getElementById('ErrorContent').innerHTML = " اطلاعات مورد نظر را انتخاب نمایید";
                document.getElementById('ErrorContent').style.display = "block";
                document.getElementById('ErrorContent').className = "msg-Yellow";
            }
        })
        function DoAction() {
            var list = [];
            $('#RiverForm input:checked').each(function () {
                if( url == '@Url.Action("ChangeRiverARStatus", "WaterResourcesManagement")')
                {
                    var Ar= $('#RiverForm').find("input[value='"+this.id+"']").attr('id');
                    list.push(Ar);
                }
                else{
                    list.push(this.id);}
            });
            var parameters = {};
            parameters = JSON.stringify({ "Id": list, AreaID: @Request.QueryString["AreaID"] });

            $.ajax({
                url: url,
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: "html",
                traditional: true,
                data: parameters,
                success: function (data, textStatus, jqXHR) {
                    $('#updateAjax').html(data);
                },
                error: function (data) {
                    $('#updateAjax').html(data);
                }
            });
        }
    });
</script>

1 个答案:

答案 0 :(得分:0)

我在所有jquery代码中添加if(!request.isjax())并且它可以正常工作