如何在textField中检测到Backspace Appcelerator Android

时间:2017-07-10 14:03:10

标签: android titanium appcelerator

如何在$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); 内的Android上的Appcelerator中检测Backspace? 事件TextFieldchange不起作用。

keypressed

1 个答案:

答案 0 :(得分:2)

使用"更改"事件并比较textfield.value。如果它小于旧值,则用户删除了一些内容:

var text_phone_1 = Ti.UI.createTextField({
    top: 40,
    left: '22.5%',
    width: '100%',
    returnKeyType: Titanium.UI.RETURNKEY_DONE,
    keyboardType: Titanium.UI.KEYBOARD_PHONE_PAD,
    hintText: '●',
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
    maxLength: 100,
});

var oldText = text_phone_1.value;

text_phone_1.addEventListener("change",function(e){
    var lessText = (text_phone_1.value.length < oldText.length);
    oldText = text_phone_1.value;
    if (lessText) {
        alert("Backspace");
    }
})