开发者

jQuery Blur only once clicked off

I have the follow HTML

<div id="outerID">
  <input id="inner1" type="text" value="button1"/>
  <input id="inner2" type="text" value="button2"/>
  <table>
    <tbody>
      <tr>
       <td>
         <input id="inner3" type="text" valu开发者_JAVA技巧e="button2"/>
       </td>
      </tr>
    </tbody>
  </table>
</div>

With the following jQuery

jQuery('#outerID').live('blur', function () {
    alert('fire');
});

I only want "blur" to fire when a click is OUTSIDE of id="outerID" - a user can click inside as many times as they want inside id=outerId but if they 'click off' id=outerId then blur ?


Try this:

var insideDiv = "";

jQuery('div#outerID').live('click', function (e) {
    if(insideDiv != "" && insideDiv  != 'outerID'){
        alert('fire');
    }
    insideDiv  = "outerID";
    return false;
});

jQuery('div#outerID2').live('click', function (e) {
    if(insideDiv != ""&& insideDiv  != 'outerID2'){
        alert('fire');
    }
    insideDiv  = "outerID2";
    return false;
});

I assume outerID2 is the id of the other div.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜