获取iframe中元素的Y位置

编程入门 行业动态 更新时间:2024-10-26 00:18:58
本文介绍了获取iframe中元素的Y位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我认为已经有人问过这个问题,我有一个iframe页面,其中有近10个文本字段,每当用户点击任一文本字段时,我都想知道该页面的Y位置.有可能吗?

I think this has been asked already, I have an iframe page where we have nearly 10 textfield's, whenever the user taps on any one of the textfield, I would like to know the Y position in that page. Is that possible?

推荐答案

这未经测试,但应为您指明正确的方向.

This is untested, but should point you in the right direction.

jQuery

$(document).ready(function(){ var iframe = $('iframe'); var inputs = iframe.find('input'); $.each(inputs, function(){ $(this).click(function(){ console.log($(this).offset().top)); }) }) })

香草Javascript

根据评论进行了更新.也未经测试.

Updated as per comment. Also untested.

为您的iframe提供一个ID,以使其更易于定位,然后:

var iframe = document.getElementById('iframe'); var inputs = Array.prototype.slice.call(iframe.getElementsByTagName('input')); inputs.forEach(function(input,i){ input.addEventListener('click', function(){ console.log(this.getBoundingClientRect().top; }) })

更多推荐

获取iframe中元素的Y位置

本文发布于:2023-10-07 23:45:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470878.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   位置   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!