Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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 选择默认类作为';主动';打开iframe_Javascript_Css_Iframe - Fatal编程技术网

Javascript 选择默认类作为';主动';打开iframe

Javascript 选择默认类作为';主动';打开iframe,javascript,css,iframe,Javascript,Css,Iframe,我有一段代码,每次用户单击按钮时都会打开一个不同的iframe。但是我注意到,当有人加载页面时,没有任何“默认”iframe可打开,因此iframe看起来是黑色和空的。有没有办法编辑代码,让一个类在默认情况下处于活动状态 $(document).ready(function() { // Catch all clicks on a link with the class 'link' $('.link').click(function(e) { // Stop the link b

我有一段代码,每次用户单击按钮时都会打开一个不同的iframe。但是我注意到,当有人加载页面时,没有任何“默认”iframe可打开,因此iframe看起来是黑色和空的。有没有办法编辑代码,让一个类在默认情况下处于活动状态

$(document).ready(function() {
  // Catch all clicks on a link with the class 'link'
  $('.link').click(function(e) {

  // Stop the link being followed:
  e.preventDefault();

  // Get the div to be shown:
  var content = $(this).attr('rel');

  // Remove any active classes:
  $('.active').removeClass('active');

  // Add the 'active' class to this link:
  $(this).addClass('active');

  // Hide all the content:
  $('.content').hide();

  // Show the requested content:
  $('#' + content).show();
});

您可以尝试这样的方法,它会尝试在页面加载时显示您的第一个链接。我不能测试,因为我没有你所有的代码,但希望这是接近你所寻找的

  $(document).ready(function() {

    showLink($('.link').first());

    // Catch all clicks on a link with the class 'link'
    $('.link').click(function(e) {
        e.preventDefault();
        showLink($(this));    
    });

    function showLink(ele){

          // Get the div to be shown:
          var content = ele.attr('rel');

          // Remove any active classes:
          $('.active').removeClass('active');

          // Add the 'active' class to this link:
          ele.addClass('active');

          // Hide all the content:
          $('.content').hide();

          // Show the requested content:
          $('#' + content).show();
    }
});
需要HTML和CSS在注释或代码段中(使用注释工具栏上的第7个图标)