jQuery blur event with ID and value

2019-09-07 08:25发布

I want to use the 'blur' event in the jQuery text plugin. http://jqueryte.com

$ ('textarea'). jqte ({
blur: function (elem) {
// ID textarea?
// Content editor?
}
});

The function of the blur, I would like to determine the content and the ID of the textarea.

Can you help me with an idea?

1条回答
别忘想泡老子
2楼-- · 2019-09-07 08:51

Since it doesn't look like the blur event is passing any arguments to the callback you might have to do something like

$("textarea").each(function(idx, elem) {
  $(this).jqte({
    blur: function() {
      console.log('blur', this, arguments);
      console.log(elem.id);
      $('#log').append('<div>' + elem.id + '</div>')
    }
  });
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-te/1.4.0/jquery-te.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-te/1.4.0/jquery-te.js"></script>

<div id="log"></div>
<textarea id="t1"></textarea>
<br />
<textarea id="t2"></textarea>
<br />
<textarea id="t3"></textarea>
<br />

查看更多
登录 后发表回答