每次点击特定按钮时,都将注意力集中在iframe上 [英] Focus on iframe every time I click on specific button
本文介绍了每次点击特定按钮时,都将注意力集中在iframe上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我点击<button class="bold" >bold</button>
时,我都希望专注于iframe
但只有一次
这是我的代码:
JavaScript :
I want to focus on iframe every time I click on <button class="bold" >bold</button>
But It Only Works one time
Here is my code :
JavaScript :
function iFrameStart() {
iframe.document.designMode="On";
}
document.addEventListener("DOMContentLoaded",iFrameStart,false);
$(document).ready(function () {
$(".bold").click(function () {
iframe.document.execCommand('bold',false,null);
document.getElementById("iframe").focus();
});
});
HTML :
<div class="container">
<h1>Editor Demo</h1>
<div class="button-wrapper">
<button class="bold">B</button>
</div>
<label><textarea name="" id="" cols="30" rows="10"></textarea></label>
<iframe id="iframe" name="iframe" ></iframe>
</div>
推荐答案
也许这是您的解决方案.
Maybe it is a solution for you.
$('#iframe').contents().find('html').focus();
还有香草js
const frame = document.querySelector('#iframe').contentWindow;
frame.document.querySelector('body').focus();
这篇关于每次点击特定按钮时,都将注意力集中在iframe上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文