我有这个iframe:
<div onmousedown="alert()">
<iframe id="PropertyCtrl" name="PropertyCtrl" frameborder="0" style="border:thick solid #0000FF; cursor:w-resize;"></iframe>
</div>
我需要创建包装iframe的边框,当我在边框上导航并且必须触发点击onmousedown
事件时。
如何创建onmousedown
事件的边框?
答案 0 :(得分:1)
只需在div
上添加边框,就可以在iframe周围添加边框:
<div class="frame-border" ...>
<iframe ... />
</div>
然后使用CSS:
.frame-border {
border: thick solid #0000FF; /* Or whatever */
}
或者如果您更喜欢内联样式:
<div style="border: thick solid #0000FF" ...>
<iframe ... />
</div>
答案 1 :(得分:1)
请检查以下代码:
function borderShow()
{
document.getElementById('PropertyCtrl').style = 'border:thick solid #00FFFF;';
}
&#13;
<div onmousedown="borderShow()">
<iframe id="PropertyCtrl" name="PropertyCtrl" frameborder="0" style="border:thick solid #0000FF; cursor:w-resize;"></iframe>
</div>
&#13;
答案 2 :(得分:1)
.off
和.on
类之间切换。classList.add/remove
用于操纵类。
function outlineTarget(tgt) {
var target = document.querySelector(tgt);
if (target.classList.contains('off')) {
target.classList.add('on');
target.classList.remove('off');
} else {
target.classList.add('off');
target.classList.remove('on');
}
}
#ctrl.off {
border: 0 solid #0000FF;
transition: all 1s ease-out;
}
#ctrl.on {
border: 10px ridge #0000FF;
border-radius: 12px;
transition: all 1s ease-out;
}
<div onclick="outlineTarget('#ctrl')">
<iframe id="ctrl" name="ctrl" class='off' src="http://example.com" frameborder="0"></iframe>
<p>Click anywhere on this text or to the right of iframe</p>
</div>