【问题标题】:Jquery and IE10jQuery 和 IE10
【发布时间】:2013-08-02 14:29:58
【问题描述】:

我有三个输入字段,input1、input2 和 input3。

当input1的值改变时,input2也相应设置:

$('input[name=input1]').change(function () {
        console.debug("input1");
    $('input[name=input2]').val($(this).val());
    $('input[name=input3]').prop("disabled", true);
});


$('input[name=input2]').change(function () {
    console.debug("input2");

    ...
});

它可以工作,但不能在 IE10 上。它不会在控制台“input1”和“input2”上打印,也不会更改 input2 的值。

编辑

问题似乎也在 IE 中

如果我将onkeyup 一起使用,它似乎可以工作。

但是如果用户使用鼠标选择一个缓存值呢?

mouseenter 有一个奇怪的效果。

【问题讨论】:

    标签: jquery internet-explorer internet-explorer-10


    【解决方案1】:

    为什么不使用 'console.log' 而不是 'console.debug' 并检查 IE 是否有问题!

    【讨论】:

    • 我想你明白了。 Object doesn't support property or method 'debug'
    • @Aditya:console.log 或者没有console.log 和console.debug 都一样
    • 也许您可以为每个输入提供特定的 id,并使用 .val() 从这些输入中获取值,然后将 'this' 替换为元素 'id' 以保持 IE 的简单性?
    • @Aditya:我已经尝试过使用 $('input[name=input2]').val($(input[name=input1]).val());但什么也没发生
    • 试试 $('#input2').val($('#input1').val());其中 input1 和 input2 是 ID ..
    【解决方案2】:

    如果你使用最新的 jQuery,你可以尝试像这样绑定事件监听器

    $(document).on('change','#input1',changeFunction) 
    

    您可能使用的旧版本

    $('#input1').on('change',changeFunction)
    

    然后使用 changeFunction(event) 做任何事情

    【讨论】:

    • 如果我将onkeyup 一起使用,它似乎可以工作。但是如果用户使用鼠标选择一个缓存值呢? mouse enter有一个奇怪的效果
    猜你喜欢
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    相关资源
    最近更新 更多