简体   繁体   中英

jQuery combobox attach an on blur event

I am referring the following url http://jqueryui.com/autocomplete/#combobox to render comboBoxes in my HTML page. I want to attach a blur event to my comboBox so that when a user clicks on the comboBox and then moves to the next field I can trigger a validation message. On searching I found that there is only a select eventthat can be attached that gets triggered when you select a value from the comboBox.

HTML CODE

  @Html.DropDownListFor(m => m.Reason, new SelectList(ViewBag.SelectReason, "Key", "Value"), "", new { id = "drop2", placeholder = "Select Reason" })

Jquery Code:

  $("#drop2").blur(function () {
           // here goes your code
        alert("blur");
    });

Is there any way that I can trigger an onBlur event ?

You should still have something like this in your page to be able to enable combobox : <select id="combobox">

Then, you can directly use jquery to apply blur event on the select element:

$("#combobox").blur(function(){
    // here goes your code
}

I finally managed to attach a blur event to my comboBox using this

     $('#myDropDownName').next().find('input').blur(function () {

      //My Action
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM