更改()事件用于IE9中的选择输入



我知道jQuery的change()方法不会在IE9中进行选择和无线电输入。但是,我发现的任何解决方法都没有为我工作。

这是在所有体面浏览器中都可以使用的代码:

    $("select#orderby").change( function(e){
        console.log("order");
        $("#candidate-filters").submit();
    });

这是我看到人们在IE9中解决此问题的一种版本:

    $("select#orderby").bind( ($.browser.msie)? 'propertychange' : 'change', function(e){
        console.log("order");
        $("#candidate-filters").submit();
    });

我尝试时不起作用。控制台没有错误。什么都没有发生。我在做什么错?

编辑:当我切换到.on()方法时,我可以将页面重新加载(大概是由于.submit()操作而导致的),但是未捕获表单选择输入。页面只是重新加载,好像什么都没改变。

它有效!,但是我忽略了其他部分可能会发现有用的部分。IE不支持HTML5 form="form_id"属性,该属性使您可以在<form>标签之外放置一个表单元素。因此,一旦我能够束缚事件,我还必须将值附加到表格中:

if ($.browser.msie) {
    $("select#orderby").bind( "propertychange", function(e){
        //console.log("order");
        var update = $(this).val();
        $("#candidate-filters").append('<input type="hidden" name="orderby" value="'+ update +'" /> ');
        $("#candidate-filters").submit();
    });
} else {
    $("select#orderby").change( function(e){
        console.log("order");
        $("#candidate-filters").submit();
    });
}

我说得太早了:上面的代码仅在IE8中起作用,但IE9不起作用。有什么想法吗?

this 示例在IE9中对我来说对我有效。

jQuery

$("#test").on("change", function(){
    alert("test changed to: " + this.value)
})​;

html

<select id="test">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>

也可以选择在blur上使用,但这绝对取决于特定情况。

另外,,请建议console.log在IE中不起作用...这可能是您问题的一部分。正如@mikemccaughan在评论中指出的那样,控制台应与IES开发人员工具一起使用。

请参阅此处的兼容性表。IE似乎不支持form属性。

您是否尝试更改

   $("select#orderby").change( function(e){
        console.log("order");
        $("#candidate-filters").submit();
    });

to

   $("select#orderby").click( function(e){
        console.log("order");
        $("#candidate-filters").submit();
    });

或使用.On()或.live(),具体取决于您的jQuery版本,对我有用,也是从这里

最新更新