Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery如何使用iframes id+&引用;随便什么;?_Javascript_Jquery_Jquery Selectors - Fatal编程技术网

Javascript JQuery如何使用iframes id+&引用;随便什么;?

Javascript JQuery如何使用iframes id+&引用;随便什么;?,javascript,jquery,jquery-selectors,Javascript,Jquery,Jquery Selectors,我有这个html <div id="cont"> <div id="videowrapper" class="fitmein"> <div id="vimeoposition" style="display: block;"> <div class="fluid-width-video-wrapper" style="padding-top: 56.25%;"> <iframe id="player1" class="vimeo" src="

我有这个html

<div id="cont">
<div id="videowrapper" class="fitmein">
<div id="vimeoposition" style="display: block;">
<div class="fluid-width-video-wrapper" style="padding-top: 56.25%;">
<iframe id="player1" class="vimeo" src="http://player.vimeo.com/blablabla">
</div>
<div class="fluid-width-video-wrapper" style="padding-top: 56.25%;">
<iframe id="player2" class="vimeo" src="http://player.vimeo.com/blablabla">
</div>
</div>
</div>

现在我想用fluid width视频包装器类为每个div添加一个id。 新的ids值应该以“fluid”开头,然后是嵌套在该div中的iframe id的值

因此结果看起来像(当然没有**s,只是为了突出显示):


我该怎么做

<script type="text/javascript">
  $(function() {

      $(".fluid-width-video-wrapper").each(function(index) {
          $(this).attr("id","fluidplayer" + index);
      });

  });
</script>
应该是动态版本

$(".classname").each(function(count){$(this).attr("id","new-id"+count)});
应该是动态版本。

您应该尝试

$(".classname").each(function(count){$(this).attr("id","new-id"+count)});
.每个

你应该试试这个

.每个

像这样的东西

像这样的东西


您可以使用.each()方法找到流体宽度视频包装器类中的每个div。然后找到该div的子对象,即iframe,并获取iframe的id。然后将“流体”附加到iframe的id,并使其成为您的div的id。
这是代码

$('.fluid-width-video-wrapper').each(function() {
    var divID = $(this).children('iframe').attr("id");
    $(this).attr('id', 'fluid' + divID);
});

您可以使用.each()方法找到流体宽度视频包装器类中的每个div。然后找到该div的子对象,即iframe,并获取iframe的id。然后将“流体”附加到iframe的id,并使其成为您的div的id。
这是代码

$('.fluid-width-video-wrapper').each(function() {
    var divID = $(this).children('iframe').attr("id");
    $(this).attr('id', 'fluid' + divID);
});

为什么不使用子选择器和父选择器()


为什么不使用子选择器和父选择器()


window.onload=函数(){
var frame=document.getElementById(“frame1”);
var win=frame.contentWindow;
showMessage(“来自iFrame主页的Hello”);
};    

window.onload=函数(){
var frame=document.getElementById(“frame1”);
var win=frame.contentWindow;
showMessage(“来自iFrame主页的Hello”);
};    

非常感谢大家的大力帮助!非常感谢大家的大力帮助!请您详细说明您的答案,并添加一点关于您提供的解决方案的说明。请您详细说明您的答案,并添加一点关于您提供的解决方案的说明?
$('iframe').each(function(){
  var divObj = $(this).parent('div').attr('id',$(this).attr('id') + 1)
      alert($(divObj).attr('id'));
});
$('.fluid-width-video-wrapper').each(function() {
    var divID = $(this).children('iframe').attr("id");
    $(this).attr('id', 'fluid' + divID);
});
$('.fluid-width-video-wrapper > iframe').each(function(){
  $(this).parent().attr("id", "fluid" + $(this).attr('id')); 
});
<script type="text/javascript">
    window.onload = function() {
        var frame = document.getElementById("frame1");
        var win =  frame.contentWindow;
        win.showMessage("Hello from Main Page in iFrame");
    };    
</script>