ASP.NET AJAX CascadingDropDown 的 jQuery 更改值

发布于 2024-09-13 08:44:32 字数 641 浏览 1 评论 0原文

我可以使用 jQuery 更改 CascadingDropDown 的值,但是触发导致目标控件的子下拉列表填充数据的事件永远不会发生:

$("#<%= ddlFromCompetition.ClientID %>").change(function() {
  var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();
  $("#<%= ddlToCompetition.ClientID %>").val(fromValue); // causes value to change, but child doesn't update
});

需要明确的是,ddlFromCompetitionddlToCompetition code> 不是父/子。它是 ddlToCompetition 的子项,不会使用上述代码进行更新。使用鼠标选择 ddlToCompetition 时,其子下拉列表会按预期更新。

我尝试调用 $("#<%= ddlToCompetition.ClientID %>").change() 来尝试强制触发事件,但它不起作用。

I can use jQuery to change the value of a CascadingDropDown, but the event that fires which causes the target control's child dropdown to populate with data never happens:

$("#<%= ddlFromCompetition.ClientID %>").change(function() {
  var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();
  $("#<%= ddlToCompetition.ClientID %>").val(fromValue); // causes value to change, but child doesn't update
});

To be clear, ddlFromCompetition and ddlToCompetition are not parent/child. It's the child of ddlToCompetition that does not update using the above code. When selecting ddlToCompetition using the mouse, its child dropdown updates as expected.

I've tried calling $("#<%= ddlToCompetition.ClientID %>").change() to try to force the event to fire, but it doesn't work.

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

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

发布评论

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

评论(1

时光无声 2024-09-20 08:44:32

您需要trigger()事件

$("#<%= ddlToCompetition.ClientID %>").trigger('change');

JQuery文档:http://api.jquery.com/trigger/

此外,由于 ddlFromCompetition 的第一个更改事件处理程序在 ddlFromCompetition 的上下文中触发,因此您应该能够将...更改

var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();

为...

var fromValue = $(this).val();

You need the trigger() event

$("#<%= ddlToCompetition.ClientID %>").trigger('change');

JQuery docs: http://api.jquery.com/trigger/

Also, because the first change event handler for ddlFromCompetition fires in the context of ddlFromCompetition, you should be able to change...

var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();

to...

var fromValue = $(this).val();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文