jQuery的.change()只触发一次 [英] jQuery .change() only fires once

查看:564
本文介绍了jQuery的.change()只触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ddlCaseFiles的DropDownList。
然后,我有一个剧本,我导入包含了jQuery .change()函数来捕获事件。然后,我有一个排序DROPDOWNLIST 3单选按钮。当默认的单选按钮被加载,那么事件触发。但只要我选择另一个单选按钮,然后在事件不会再触发。

I have a DropDownList called "ddlCaseFiles". I then have a script which I import that contains the jQuery .change() function to capture the event. Then I have 3 radio buttons which sorts the dropDownList. When the default radio button is loaded, then the event fires. But as soon as I select another radio button, then the event doesn't fire anymore.

下面是我的DropDownList:

Here is my DropDownList:

<asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" 
DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" />

和这里是我的jQuery .change():

and here is my jQuery .change():

 $('#ddlCaseFiles').change(function () {
    debugger;
    $('#lblNextExhibitNumber').text('');
    var temp = $(this).val();
});

下面是一个什么样的单选按钮做剪断:

Here is a snipper of what the radio buttons do:

    protected void rbByFileName_CheckedChanged(object sender, EventArgs e)
{
    ddlCaseFiles.DataSourceID = "dsCaseFilesReverse";
    ddlCaseFiles.DataTextField = "Display";
    ddlCaseFiles.DataValueField = "FileID";
}

protected void rbByFileID_CheckedChanged(object sender, EventArgs e)
{
    ddlCaseFiles.DataSourceID = "dsCaseFiles";
    ddlCaseFiles.DataTextField = "Display";
    ddlCaseFiles.DataValueField = "FileID";
}

我从来没有()之前使用的.change。所以,也许我失去了一些东西。

I have never used the .change() before. So maybe I am missing something

推荐答案

看起来像一个单选按钮,您的CheckedChanged事件不会触发下拉更改事件。该JS变化事件在一个下拉的变化选择的值。这时候你改变并不一定发生在的DataSourceID ,不是吗?

Looks like your CheckedChanged events of the radio buttons don't trigger the dropdown change event. The JS change event fires when the selected value of a drop down changes. This doesn't necessarily happen when you change the DataSourceID, does it?

我不知道如何在ASP触发此。也许 ddlCaseFiles.SelectedIndexChanged()

I'm not sure how to trigger this in ASP. Perhaps ddlCaseFiles.SelectedIndexChanged()?

否则,你可以单击事件处理程序添加到电台:

Otherwise, you could add a click event handler to the radios:

$('input[type="radio"].someCssClass').click(function(){
   $('#ddlCaseFiles').trigger('change');
});

编辑:

这只是一个猜测,但它看起来像的CheckedChanged 可能会被修改&LT;选择&GT; 元素在页面上。例如,是否重新插入每次的DataSourceID 的变化?

This is just a guess, but it looks like the CheckedChanged might be modifying the <select> element on the page. For example, is it reinserted every time DataSourceID changes?

尝试使用。对()功能改变你的下拉更改事件处理程序是这样的:

Try changing your dropdown change event handler like this using the .on() function:

$('body').on('change', '#ddlCaseFiles', function () {
    debugger;
    $('#lblNextExhibitNumber').text('');
    var temp = $(this).val();
});

注:为更好的性能变化 $('身体')一些容器接近下拉

.change()附加功能的变更处理一个元素的页面上。如果ASP将一个元素并重新添加它以后再处理也没有了。

The .change() function attaches the change handler to an element on a page. If ASP removes an element and re-adds it later then the handler is gone.

一个使用的处理程序,即使元素被删除了。对()功能仍然存在连接。 在这里阅读更多。

A handler attached using the .on() function persists even if the element is removed. Read more here.

这篇关于jQuery的.change()只触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆