0

iframe我在我的网站中使用了以下内容

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
 jQuery('#video1').click(function(){
   alert($(this).attr('id'));
  });
</script>

<iframe id="video1" width="520" height="360" src="http://www.youtube.com/embed/TJ2X4dFhAC0?enablejsapi" frameborder="0" allowfullscreen></iframe>

我需要获取iframe 视频idiframeonclick,我该怎么做?

4

3 回答 3

1

通过从同一标签访问它来获取标签的价值似乎很疯狂。我不知道你在做什么。如果你有很多 iframe,那么你可以说我想获取被点击的 iframe 的 id。那么单身你可以做到这一点

  $('#video1').click(function(){
   alert($(this).attr('id'));
  });
于 2012-11-28T13:09:15.717 回答
1

我假设您有多个 iframe,因此目标是确定他们点击了哪一个?如果是这样,这应该工作:

$(function() { //Attach to the jquery onLoad function
    $('iframe').click(function() {
        var id = $(this).id;
        console.log(id);
        // do stuff with id here
    });
});
于 2012-11-28T13:12:08.373 回答
-2
onclick='call(this)'

在 JavaScript 中

function call(ev)
{
alert(ev.id)
}

在jQuery中

function call(ev)
{
alert($(ev).attr('id'));
}
于 2012-11-28T13:06:46.510 回答