使用 JQuery 捕获 Telerik MVC ComboBoxFor 中的更改

发布于 2024-10-23 12:23:25 字数 1083 浏览 7 评论 0原文

我使用以下代码来捕获 HTML 输入中的更改文本:

$(document).ready(function() {
    $(':input', document.myForm).bind("change", function() { setConfirmUnload(true); }); 
});

这对于普通文本框和复选框来说效果很好。

我正在使用 Telerik 的 MVC ComboBoxFor 来呈现输入标签,但似乎没有触发上述 JQuery。

有什么想法如何捕捉这个吗?

HTML 的呈现方式如下:

<div class="t-widget t-combobox t-header" id="InterviewRequired">
<div class="t-dropdown-wrap t-state-default">
    <input class="t-input" id="InterviewRequired-input" name="InterviewRequired-input" title="InterviewRequired" type="text" value="Select" />
    <span class="t-select t-header">
        <span class="t-icon t-arrow-down">select</span>
    </span>
</div>
<input id="InterviewRequired-value" name="InterviewRequired" style="display:none" type="text" value="0" />

我还在 Telerik 论坛,以防我在这里得不到答案。

I am using the following code to capture change text in HTML inputs:

$(document).ready(function() {
    $(':input', document.myForm).bind("change", function() { setConfirmUnload(true); }); 
});

this works fine for normal textboxes and checkboxes.

I'm using Telerik's MVC ComboBoxFor which renders input tags, but does not seem to trigger the above JQuery.

Any ideas how to capture this?

This is how the HTML renders:

<div class="t-widget t-combobox t-header" id="InterviewRequired">
<div class="t-dropdown-wrap t-state-default">
    <input class="t-input" id="InterviewRequired-input" name="InterviewRequired-input" title="InterviewRequired" type="text" value="Select" />
    <span class="t-select t-header">
        <span class="t-icon t-arrow-down">select</span>
    </span>
</div>
<input id="InterviewRequired-value" name="InterviewRequired" style="display:none" type="text" value="0" />

I've also asked this question on the Telerik forums in case I don't get an answer here.

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

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

发布评论

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

评论(2

冰火雁神 2024-10-30 12:23:25

以下是您可以附加到的事件列表:
http://www.telerik.com/community/forums/aspnet- mvc/combobox/jquery-event-names.aspx

如果您想使用 JavaScript 以更动态的方式附加更改事件,您可以附加到“valueChange”事件而不是“change”:

$(document).ready(function() {
    $('#ComboBoxId').bind("valueChange", function() { setConfirmUnload(true); }); 
});

Heres a list of events you can attach to:
http://www.telerik.com/community/forums/aspnet-mvc/combobox/jquery-event-names.aspx

If you want to attach the change event in a more dynamic way with javascript, you would attach to the "valueChange" event and not "change":

$(document).ready(function() {
    $('#ComboBoxId').bind("valueChange", function() { setConfirmUnload(true); }); 
});
德意的啸 2024-10-30 12:23:25

请在此处查看演示。 ComboBox 被渲染为 和弹出

<div class="t-dropdown-wrap t-state-default">
  <input type="text" value="Chai" name="ComboBox-input" id="ComboBox-input" class="t-input" autocomplete="off">
  <span class="t-select t-header">
    <span class="t-icon t-arrow-down">select</span>
  </span>
</div>

查看客户端文档,您很可能需要注册一个客户端事件位于此处

   <%= Html.Telerik().ComboBox()
            .Name("ComboBox")
            .ClientEvents(events => events
                .OnChange("onChange")
            )
    %>

    <script type="text/javascript">
        function onChange(e) {
           setConfirmUnload(true);
        }
    </script>

看起来你应该只能从这个例子中使用 jQuery 来做到这一点:

<%= Html.Telerik().ComboBox().Name("ComboBox") %>

<script type="text/javascript">
    $(document).ready(function() {
        $('#ComboBox').bind('change', function(e) { // your code });
    });
</script>

也许可以尝试:

$(document).ready(function() {
    $('#myComboBox').bind("change", function() { setConfirmUnload(true); }); 
});

Looking at the demo here. The ComboBox is being rendered as <input/> and a popup <div/>

<div class="t-dropdown-wrap t-state-default">
  <input type="text" value="Chai" name="ComboBox-input" id="ComboBox-input" class="t-input" autocomplete="off">
  <span class="t-select t-header">
    <span class="t-icon t-arrow-down">select</span>
  </span>
</div>

looking at the client side docs, you most likely will need to register a Client-side event located here.

   <%= Html.Telerik().ComboBox()
            .Name("ComboBox")
            .ClientEvents(events => events
                .OnChange("onChange")
            )
    %>

    <script type="text/javascript">
        function onChange(e) {
           setConfirmUnload(true);
        }
    </script>

it also looks like you should be able to do it with jQuery only from this example:

<%= Html.Telerik().ComboBox().Name("ComboBox") %>

<script type="text/javascript">
    $(document).ready(function() {
        $('#ComboBox').bind('change', function(e) { // your code });
    });
</script>

Maybe try:

$(document).ready(function() {
    $('#myComboBox').bind("change", function() { setConfirmUnload(true); }); 
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文