【问题标题】:How to capture input's type = 'text' clear event?如何捕获输入的 type = 'text' 清除事件?
【发布时间】:2014-11-09 00:21:12
【问题描述】:

<input type='text' onchange="reportAnswer(1, this.value);" onkeyup="this.onchange();" onpaste="this.onchange();" oncut="this.onchange();" onclear = "this.onchange();" />

如何捕捉这种变化?这是 IE11。

附:我添加了onclear 处理程序,因为我已经没有什么想法了。

【问题讨论】:

标签: javascript html input textbox


【解决方案1】:

你可以使用“oninput”:

// Try to change value of the input below
<input id="input1" />

var input = document.getElementById("input1");
input.oninput = function(){alert("Value changed");}

【讨论】:

    【解决方案2】:

    你还没有说[x] 提供了什么,这可能是相关的,但你还没有尝试过的一个事件是input 所以:Live Example

    <input type='text'
        onchange="reportAnswer(1, this.value);"
        onkeyup="this.onchange();"
        onpaste="this.onchange();"
        oncut="this.onchange();"
        oninput="this.onchange();" />
    

    (不知道它是否有效,IE11 不会在 Windows 8.1 上为我添加该框。)

    不过,更有可能的是,您需要连接到提供 [x] 的任何东西所提供的东西。

    【讨论】:

    • P.S. -1 不是我的,这是 IE11。
    • @Kosmos:查看问题评论。
    • oninput 帮助了我:O 谢谢。但是不知道为什么IE11不为你添加同样的东西。
    • 是的。可悲的是,这让我的reportAnswer 在其他情况下执行得比需要的多,但我会以某种方式解决它:P
    猜你喜欢
    • 2019-04-03
    • 1970-01-01
    • 2017-08-11
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多