问题
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:
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 />
来源:https://stackoverflow.com/questions/28082631/jquery-blur-event-with-id-and-value