javascript - Type and focus out event in jquery? -
i have written blur()
event handle focus out event on text field. code looks this.
$("input[type=text]").blur(function (event) { if(this.value){ //do } event.originalevent.handled = true; });
i have situation text-field automatically getting focus text previous page.
to give example, in flipkart.com
, type text in search field , click search. event handler
must execute focus out event. (it happening correctly).
in next page, text entered prepopulated in text-field , focus on it. in page, if action, text-field lose focus , same event gets called again. don't need happen.
is there way avoid this? combining 2 event handlers? please help.
change code function bound element after user explicitly interacts element so:
$("input[type=text]").on('keyup keypress change click', function() { $("input[type=text]").blur(function(event) { if (this.value) { //do alert('blur called after interacting element'); } event.originalevent.handled = true; }); }); $('#test').focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="test" value="some value">
Comments
Post a Comment