获取 Summernote 元素的 ID
Get ID of Summernote Element
我打算在一个页面上有多个 summernote 字段,并且我想要一种在执行 onblur 时动态获取元素 ID 的方法。我似乎无法获取元素 ID,它只是返回 undefined
示例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);
}
});
});
你用的是哪个版本的summernote??如果它是 v0.6.5 或更高版本,则使用驼峰式大小写,即 onBlur 而不是 onblur 。试试这个并检查。另外 post 你得到了什么错误,如果有的话。此外,缺少回调函数。检查 http://summernote.org/deep-dive/
callbacks 你的情况缺少 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!");
}
}
});
我打算在一个页面上有多个 summernote 字段,并且我想要一种在执行 onblur 时动态获取元素 ID 的方法。我似乎无法获取元素 ID,它只是返回 undefined
示例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);
}
});
});
你用的是哪个版本的summernote??如果它是 v0.6.5 或更高版本,则使用驼峰式大小写,即 onBlur 而不是 onblur 。试试这个并检查。另外 post 你得到了什么错误,如果有的话。此外,缺少回调函数。检查 http://summernote.org/deep-dive/
callbacks 你的情况缺少 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!");
}
}
});