级联下拉列表不起作用

发布于 2024-09-24 19:01:12 字数 1692 浏览 2 评论 0原文

我尝试更改级联下拉列表示例 http://www.codedigest.com/Articles/ jQuery/224_Building_Cascading_DropDownList_in_ASPNet_Using_jQuery_and_JSON.aspx

但我总是收到消息“Microsoft JScript 运行时错误:预期对象”

也许有人有想法?

<asp:Content ID="Content1" ContentPlaceHolderID="contentplaceholderHEAD" runat="Server">
</script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript">
<script language="javascript">
    $(document).ready(function () {
        $("#<%=Ticket_ArtDropDownList.ClientID %>").change(function() {
            $("#<%=Ticket_StatusSelect.ClientID %>").html("");
            var Ticket_Art = $("#<%=Ticket_ArtDropDownList.ClientID %> > option:selected").attr("value");
            if (Ticket_Art != 0) {
                $.getJSON('Ticketdetails.ashx?Ticket_Art=' + Ticket_Art, function(cities) { //wozu dient dieses "cities" ?
                    $.each(cities, function() {
                        $("#<%=Ticket_StatusSelect.ClientID %>").append($("</option>").val(this['Ticket_Art']).html(this['Text']));
                    });
                });
            }
        });
    });
</script>

无法将我的所有代码标记为“Sourceode”,因为它无法正常工作。

<asp:Content ID="Content2" ContentPlaceHolderID="maincontent" runat="Server">
<div>

票证_ID: 门票_艺术: 票证状态:

i tried to change an cascading dropdownlist example http://www.codedigest.com/Articles/jQuery/224_Building_Cascading_DropDownList_in_ASPNet_Using_jQuery_and_JSON.aspx

But i get always the message "Microsoft JScript runtime error: Object expected"

Maybe someone has an idea?

<asp:Content ID="Content1" ContentPlaceHolderID="contentplaceholderHEAD" runat="Server">
</script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript">
<script language="javascript">
    $(document).ready(function () {
        $("#<%=Ticket_ArtDropDownList.ClientID %>").change(function() {
            $("#<%=Ticket_StatusSelect.ClientID %>").html("");
            var Ticket_Art = $("#<%=Ticket_ArtDropDownList.ClientID %> > option:selected").attr("value");
            if (Ticket_Art != 0) {
                $.getJSON('Ticketdetails.ashx?Ticket_Art=' + Ticket_Art, function(cities) { //wozu dient dieses "cities" ?
                    $.each(cities, function() {
                        $("#<%=Ticket_StatusSelect.ClientID %>").append($("</option>").val(this['Ticket_Art']).html(this['Text']));
                    });
                });
            }
        });
    });
</script>

Can't tag all my code as "Sourceode" because its not working corectly..

<asp:Content ID="Content2" ContentPlaceHolderID="maincontent" runat="Server">
<div>

Ticket_ID:
Ticket_Art:

Ticket_Status:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美的太阳 2024-10-01 19:01:13

对我来说最突出的是你的脚本标签...我不相信 jQuery 被正确包含,这:

</script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript">

应该是:

<script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript"></script>

还要检查你的源代码,确保 ~/ 被解析为最终 HTML 中的正确目录。同样在循环中,$("") 应该是:$("

最后一个建议是您可以直接在

var Ticket_Art = $("#<%=Ticket_ArtDropDownList.ClientID %>").val();

What stands out at me is your script tag...I don't believe jQuery is being included correctly, this:

</script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript">

Should be:

<script src="~/_scripts/jQuery-1.4.2.js" type="text/javascript"></script>

Also check your source, make sure the ~/ is being resolved to the correct directory in the final HTML. Also in your loop, $("</option>") should be: $("<option/>").

The last suggestion is you can use .val() directly on a <select> to get the current value, like this:

var Ticket_Art = $("#<%=Ticket_ArtDropDownList.ClientID %>").val();
春风十里 2024-10-01 19:01:13
  • jQuery 文件的路径不正确。
  • 设置选项不正确。响应中没有 Ticket_Art,而是 Ticket_Status。
  • Path to jQuery File was not correct.
  • setting the options was not correct. There was no Ticket_Art but Ticket_Status in the response.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文