Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.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 单选按钮的功能不工作?_Javascript_Html_Function - Fatal编程技术网

Javascript 单选按钮的功能不工作?

Javascript 单选按钮的功能不工作?,javascript,html,function,Javascript,Html,Function,我有3个单选按钮的值:视频,音乐和新闻。我正在通过单选按钮调用该函数。在我的函数中,我有一个.onclick函数,用于按钮实际显示iFrame 我试过使用onClick,但也不行 HTML: JavaScript: 您应该创建一个类似triggerC的函数,并在单选按钮代码上的onclick中调用它,并且当您调用video时,有许多为null的gelELementByid将它们删除。但主要问题是,onclick函数video正在工作,但用于呈现视频文档的代码。getElementById'dis

我有3个单选按钮的值:视频,音乐和新闻。我正在通过单选按钮调用该函数。在我的函数中,我有一个.onclick函数,用于按钮实际显示iFrame

我试过使用onClick,但也不行

HTML: JavaScript:
您应该创建一个类似triggerC的函数,并在单选按钮代码上的onclick中调用它,并且当您调用video时,有许多为null的gelELementByid将它们删除。但主要问题是,onclick函数video正在工作,但用于呈现视频文档的代码。getElementById'displayAll'。onclick未被触发。您必须显式地调用它,就像我对函数triggerC所做的那样。希望这有帮助

function video() {
//Input field (genre)
console.log("hi")
var genre = document.getElementById('genre').value;
genre = genre.toLowerCase();
//Select menu genre choose.
//var genreOption = document.getElementById('genreList').value;

//Embeding codes
var embedComedy = new Array('QqhtaHY1yjQ', 'ptYA1k1JPeQ', 'mYHGPUqEOJY', 'mYHGPUqEOJY', 'VY4HObQw5Go', 'DiKCJaBUmRs', 'LAeUtlcETfc', 'xwGERoFtQoM', 'QqhtaHY1yjQ', 'VY4HObQw5Go', '3meqBxtY4dE');
var embedMisc = new Array('hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU');
var embedSport = new Array('cBJyo0tgLnw', 'uIBgWI_BTyM', 'Vs0QoCtvJmk');
var embedDocumentary = new Array('PyQVjlE3zkU', 'bkprsIaoIv0', 'P4ynv-vRHKQ', 'tnpaaVB4XyA');

//Holds embed codes when being looped (total 12).
var videoEmbed = new Array(12); //Holds Embed Codes When Looped

//Select menu value - number of videos.
var numVideos = document.getElementById('numVid').value;

//Onclick display the embeded videos.
function triggerC() {
    genre = 'video';
    if (genre == 'video' || genre == 'comedi' || genre == 'com' || genre == 'funny' || genre == 'fun') {
        console.log(numVideos);
        for (var i = 0; i < numVideos; i++) {
            console.log(numVideos);
            videoEmbed[i] += "<iframe width='560' height='315' src='//www.youtube.com/embed/" + embedComedy[i] + "'" + "frameborder='0' allowfullscreen></iframe><br /><hr width='90%'/>";
            document.getElementById('videos').innerHTML = videoEmbed;
        }
    }
}

document.getElementById('displayAll').onclick = function() {
    triggerC()

}
triggerC()

}

尝试onchange事件而不是onclick。为什么要初始化“displayAll”。视频功能中的onclick?您可以在窗口中初始化它。onload。。。我在回答中添加了小演示
function video() {
  //Input field (genre)
  var genre = document.getElementById('genre').value;
  genre = genre.toLowerCase();
  //Select menu genre choose.
  var genreOption = document.getElementById('genreList').value;

  //Embeding codes
  var embedComedy = new Array('QqhtaHY1yjQ', 'ptYA1k1JPeQ', 'mYHGPUqEOJY', 'mYHGPUqEOJY', 'VY4HObQw5Go', 'DiKCJaBUmRs', 'LAeUtlcETfc', 'xwGERoFtQoM', 'QqhtaHY1yjQ', 'VY4HObQw5Go', '3meqBxtY4dE');
  var embedMisc = new Array('hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU');
  var embedSport = new Array('cBJyo0tgLnw', 'uIBgWI_BTyM', 'Vs0QoCtvJmk');
  var embedDocumentary = new Array('PyQVjlE3zkU', 'bkprsIaoIv0', 'P4ynv-vRHKQ', 'tnpaaVB4XyA');

  //Holds embed codes when being looped (total 12).
  var videoEmbed = new Array(12); //Holds Embed Codes When Looped

  //Select menu value - number of videos.
  var numVideos = document.getElementById('numVideos').value;

  //Onclick display the embeded videos.
  document.getElementById('displayAll').onclick = function() {
    if (genre == 'comedy' || genre == 'comedi' || genre == 'com' || genre == 'funny' || genre == 'fun') {
      for (var i = 0; i < numVideos; i++) {
        videoEmbed[i] += "<iframe width='560' height='315' src='//www.youtube.com/embed/" + embedComedy[i] + "'" + "frameborder='0' allowfullscreen></iframe><br /><hr width='90%'/>";
        document.getElementById('videos').innerHTML = videoEmbed;
      }
    }
  }
}
function video() {
//Input field (genre)
console.log("hi")
var genre = document.getElementById('genre').value;
genre = genre.toLowerCase();
//Select menu genre choose.
//var genreOption = document.getElementById('genreList').value;

//Embeding codes
var embedComedy = new Array('QqhtaHY1yjQ', 'ptYA1k1JPeQ', 'mYHGPUqEOJY', 'mYHGPUqEOJY', 'VY4HObQw5Go', 'DiKCJaBUmRs', 'LAeUtlcETfc', 'xwGERoFtQoM', 'QqhtaHY1yjQ', 'VY4HObQw5Go', '3meqBxtY4dE');
var embedMisc = new Array('hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU', 'hC3VTgIPoGU');
var embedSport = new Array('cBJyo0tgLnw', 'uIBgWI_BTyM', 'Vs0QoCtvJmk');
var embedDocumentary = new Array('PyQVjlE3zkU', 'bkprsIaoIv0', 'P4ynv-vRHKQ', 'tnpaaVB4XyA');

//Holds embed codes when being looped (total 12).
var videoEmbed = new Array(12); //Holds Embed Codes When Looped

//Select menu value - number of videos.
var numVideos = document.getElementById('numVid').value;

//Onclick display the embeded videos.
function triggerC() {
    genre = 'video';
    if (genre == 'video' || genre == 'comedi' || genre == 'com' || genre == 'funny' || genre == 'fun') {
        console.log(numVideos);
        for (var i = 0; i < numVideos; i++) {
            console.log(numVideos);
            videoEmbed[i] += "<iframe width='560' height='315' src='//www.youtube.com/embed/" + embedComedy[i] + "'" + "frameborder='0' allowfullscreen></iframe><br /><hr width='90%'/>";
            document.getElementById('videos').innerHTML = videoEmbed;
        }
    }
}

document.getElementById('displayAll').onclick = function() {
    triggerC()

}
triggerC()