我将在一个页面上有多个summernote字段,并且我希望在执行onblur时获得元素ID的动态方法。我似乎无法得到元素id,它只是返回未定义的
示例HTML
<div class="summernote" id="desc_long" name="Long Description">Test 123</div>
Javascript
$(function () {
$('.summernote').summernote({
toolbar: [
['headline', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['color', ['color']],
['font', ['strikethrough', 'superscript', 'subscript']],
['alignment', ['ul', 'ol', 'paragraph']],
['insert', ['link']],
],
onblur: function() {
var objid = $(this).attr("id");
alert(objid);
}
});
});发布于 2016-11-07 04:22:48
你用的是哪种版本的夏季便笺??如果是v0.6.5或更高,那么使用骆驼案例,即onBlur而不是onblur。试试这个检查一下。另外,如果你有什么错误的话,也要贴出你的错误。此外,还缺少回调函数。检查http://summernote.org/deep-dive/
发布于 2016-11-07 04:24:36
在您的情况下缺少回调 attr。
$('.summernote').summernote({
toolbar: [
['headline', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['color', ['color']],
['font', ['strikethrough', 'superscript', 'subscript']],
['alignment', ['ul', 'ol', 'paragraph']],
['insert', ['link']],
],
callbacks: {
onBlur: function( event ) {
console.log($(this).attr('id'))
//alert("onBlur event triggered!");
}
}
});https://stackoverflow.com/questions/40457758
复制相似问题