Domanda

How to clear easyui combobox input on click? Looked for onClick event on editor but didn't find. Tried to bind event on input class but didn't work.

È stato utile?

Soluzione

The combo box isn't created until after the DOM is rendered, so you have to use event delegation to target its focus and blur events

$("body").on("focus", "input.combo-text", function(){
    $(this).data("prev-value", this.value);
    this.value = "";
})
.on("blur", "input.combo-text", function(){
    if ($(this).val() === ""){
        $(this).val($(this).data("prev-value"));
    }
    $(this).data("prev-value", "");
});

As you can see, when the input receives focus, we are storing the previous value as a data attribute on the element, then retrieving it when focus is lost if the user didn't input anything different.

Demo

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top