这是我的HTML:
<img src="Image/icons/preview.png" alt="Preview" id="imgPreviewHeader" onclick="ViewHtml(this.id);" />
<textarea rows="30" cols="22" id="txtHeader" class="editor"></textarea>`
Run Code Online (Sandbox Code Playgroud)
和JavaScript代码:
$("#" + imgPreviewHeader).closest('textarea.editor').ckeditorGet().execCommand('source');
Run Code Online (Sandbox Code Playgroud)
有谁能够帮我..?
你需要在这里使用.next()因为textarea是img元素的下一个兄弟..closest()将在祖先元素中查找不匹配兄弟元素的匹配项
//assuming id has the value imgPreviewHeader
$("#" + id).next('textarea.editor').ckeditorGet().execCommand('source');
Run Code Online (Sandbox Code Playgroud)
即
$("#imgPreviewHeader").next('textarea.editor').ckeditorGet().execCommand('source');
Run Code Online (Sandbox Code Playgroud)