[英]Get id of element within ckeditor
不幸的是,我不得不對此提出一個新的問題,因為我還不能在回復中添加評論(在國外帖子中)。
在這個問題( 單擊CKEditor的內容以顯示警報 )中,Palec發布了一種解決方案,用於在CKEditor中獲取onclick事件,對我來說效果很好,但是由於我幾乎不了解jQuery,所以我需要知道如何獲取元素的ID(在此使用以下代碼在CKEditor中設置div的ID)。
這是我正在談論的代碼。
CKEDITOR.on('instanceReady', function() {
$('.cke_contents iframe').contents().click(function() {
alert('Clicked!');
});
});
感謝您的幫助,Pascal
您可以使用來獲取本機Javascript中元素的ID
element.id
並在jQuery中使用
$('element').attr('id')
工作示例:
// Native Javascript var myDiv = document.getElementsByTagName('div')[0]; var myDivId = myDiv.id; window.alert('Native javascript has found the id of the <div> is "' + myDivId + '"'); // jQuery $(document).ready(function(){ alert('jQuery Library has found the id of the <div> is "' + $('div').attr('id') + '"'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="my-div"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.