根据用户光标的位置获取 iframe ID
get iframe id according to position of user cursor
我的网页中有 2 个带有内容可编辑(true)的 iframe,我的问题是如何根据光标插入符号的位置获取 iframe ID?
例如:iframe1 和 iframe2,如果用户光标插入符号位置在 iframe2 中,那么它将提醒 id frame2
我已经尝试过以下代码
$(document).ready(function(){
$('iframe').on('change mouseup mousedown mouseout keydown', function(){
var iframeID = $(this).attr('id');
$(this).contents().unbind();
$(this).contents().bind('click', function(){
alert(iframeID);
});
});
});
但它不起作用
有什么建议吗?
可以使用mouseenter:
$(document).ready(function() {
$('iframe').mouseenter(function(h) {
var id = $(this).attr('id');
alert(id);
});
});
这里有一个小提琴:http://jsfiddle.net/saq02L9o/
使用悬停
http://api.jquery.com/hover/
$("iframe").hover(
function() {
alert('mouse in to ' + $(this).attr('id'))
}, function() {
//alert('mouse out of '+$(this).attr('id'))
}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe id="foo">foo</iframe>
<iframe id="bar">bar</iframe>
相关文章:
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- 获取iframe内容的宽度-高度
- 如何从一个友好的iframe中获取iframe实例
- 获取 iframe 内点击标签的父级
- 获取iframe中元素的Y位置
- 当我尝试使用jquery获取iframe的内容时,我得到了错误.请帮我解决
- 在没有jquery的情况下获取iframe中的特定内容
- 从父窗口获取 iframe 中文本框的值
- 无法获取 iframe 内容
- JS从内部获取iFrame的文档
- 在 chrome 中获取 iframe 正文 html 内容
- 根据用户光标的位置获取 iframe ID
- 获取 iFrame 中页面的标题
- Flex 获取 iframe 文本值
- 使用 Javascript 获取 iframe 内容
- 如何在 jQuery 中获取 iframe 原点
- 从后台页面Chrome扩展弹出窗口获取iframe
- 获取 IFrame 源,然后更新输入文本框
- 使用 javascript 按属性获取 iframe 的元素
- 如何在不将 iframe 放在页面上的情况下获取 iframe 的内容