Я пытаюсь создать искусственную и динамичную веб-радиостанцию, у которой есть полное расписание, которое я выбираю. Однако функция Check(), похоже, не заменяет существующий тег P, когда я запускаю его в функции SetInterval. Я начинаю задаваться вопросом, если мой вопрос с аргументами, если ...Функция SetInterval не устанавливает innerHTML в верхней части часа
<script type="text/javascript">
marklevin = "<p><button onclick='Control()'>Pause</button><br /><div><embed type='application/x-vlc-plugin' pluginspage='http://www.videolan.org' width='50%' height='20%' id='vlc' loop='yes' autoplay='yes' target='http://4293.live.streamtheworld.com/MARK_LEVINAAC?&uuid=15F6FB00-0000-0001-1755-1EBAEDA617CA'></embed></div></p>";
laura = "<p><button onclick='Control()'>Pause</button><br /><div><embed type='application/x-vlc-plugin' pluginspage='http://www.videolan.org' width='50%' height='20%' id='vlc' loop='yes' autoplay='yes' target='http://noxsolutions.mp3.miisolutions.net/nox/laura'></embed></div></p>";
sean = "<p><button onclick='Control()'>Pause</button><br /><div><embed type='application/x-vlc-plugin' pluginspage='http://www.videolan.org' width='50%' height='20%' id='vlc' loop='yes' autoplay='yes' target='http://prn-hannity-ic-pri.ng.akacast.akamaistream.net/7/811/60538/v1/auth.akacast.akamaistream.net/prn_hannity_ic_pri'></embed></div></p>";
cbs = "<p><button onclick='Control()'>Pause</button><br /><div><embed type='application/x-vlc-plugin' pluginspage='http://www.videolan.org' width='50%' height='20%' id='vlc' loop='yes' autoplay='yes' target='http://1451.live.streamtheworld.com:3690/CBSNEWSDIALUP_SC'></embed></div></p>";
control = 0
divs = document.getElementsByTagName("div");
ps = document.getElementsByTagName("p");
var currentdate = new Date();
hours = currentdate.getHours();
minutes = currentdate.getMinutes();
seconds = currentdate.getSeconds();
if (hours > 0 && hours < 4) {
\t document.write("Laura Ingraham Show<br />Midnight to 4");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 4) {
\t document.write("Mark Levin Show<br />4 AM");
\t document.write(marklevin);
\t set2 = "marklevin";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 5) {
\t document.write("CBS Radio News<br />5 AM");
\t document.write(cbs);
\t set2 = "cbs";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 6) {
\t document.write("Sean Hannity show<br />6 AM");
\t document.write(sean);
\t set2 = "sean";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 7) {
\t document.write("Laura Ingraham Show<br />7 AM");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 8) {
\t document.write("CBS Radio News<br />8 AM");
\t document.write(cbs);
\t set2 = "cbs";
\t div_content = divs[0].innerHTML;
\t }
if (hours > 8 && hours < 11) {
\t document.write("Sean Hannity Show<br />9 AM to 11 AM");
\t document.write(sean);
\t set2 = "sean";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 11) {
\t document.write("Laura Ingraham Show<br />11 AM");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 12) {
\t document.write("Mark Levin Show<br />NOON");
\t document.write(marklevin);
\t set2 = "marklevin";
\t div_content = divs[0].innerHTML;
\t }
if (hours > 12 && hours < 15) {
\t document.write("CBS Radio News<br />1 PM to 3 PM");
\t document.write(cbs);
\t set2 = "cbs";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 15) {
\t document.write("Mark Levin Show<br />3 PM");
\t document.write(marklevin);
\t set2 = "marklevin";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 16) {
\t document.write("Laura Ingraham Show<br />4 PM");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 17) {
\t document.write("Sean Hannity Show<br />5 PM");
\t document.write(sean);
\t set2 = "sean";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 18) {
\t document.write("Laura Ingraham Show<br />6 PM");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours > 18 && hours < 21) {
\t document.write("Mark Levin Show<br />7 PM to 9 PM");
\t document.write(marklevin);
\t set2 = "marklevin";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 21) {
\t document.write("Laura Ingraham<br />9 PM");
\t document.write(laura);
\t set2 = "laura";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 22) {
\t document.write("Sean Hannity Show<br />10 PM");
\t document.write(sean);
\t set2 = "sean";
\t div_content = divs[0].innerHTML;
\t }
if (hours == 23) {
\t document.write("Mark Levin Show<br />11 PM");
\t document.write(marklevin);
\t set2 = "marklevin";
\t div_content = divs[0].innerHTML;
\t }
function Check() {
\t currentdate = new Date();
\t hours = currentdate.getHours();
\t minutes = currentdate.getMinutes();
\t seconds = currentdate.getSeconds();
\t if (hours > 0 && hours < 4 && set2 != "laura") {
\t \t ps[0].innerHTML = "Laura Ingraham Show<br />Midnight to 4<br />" + laura
\t \t set2 = "laura";
\t \t }
\t if (hours == 4 && set2 != "marklevin") {
\t \t ps[0].innerHTML = "Mark Levin Show<br />4 AM<br />" + marklevin
\t \t set2 = "marklevin";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 5 && set2 != "cbs") {
\t \t document.write("CBS Radio News<br />5 AM");
\t \t document.write(cbs);
\t \t set2 = "cbs";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 6 && set2 != "sean") {
\t \t document.write("Sean Hannity show<br />6 AM");
\t \t document.write(sean);
\t \t set2 = "sean";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 7 && set2 != "laura") {
\t \t document.write("Laura Ingraham Show<br />7 AM");
\t \t document.write(laura);
\t \t set2 = "laura";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t // Copy this code throughout the entire page. It's more stable than before.
\t // ps[0].innerHTML =
\t // Instead of
\t // document.write(
\t if (hours == 8 && set2 != "cbs") {
\t \t ps[0].innerHTML = "CBS Radio News<br />8 AM<br />" + cbs;
\t \t set2 = "cbs";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours > 8 && hours < 11 && set2 != "sean") {
\t \t ps[0].innerHTML = "Sean Hannity Show<br />9 AM to 11 AM<br />" + sean;
\t \t set2 = "sean";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 11 && set2 != "laura") {
\t \t ps[0].innerHTML = "Laura Ingraham Show<br />11 AM<br />" + laura;
\t \t set2 = "laura";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 12 && set2 != "marklevin") {
\t \t ps[0].innerHTML = "Mark Levin Show<br />NOON<br />" + marklevin;
\t \t set2 = "marklevin";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours > 12 && hours < 15 && set2 != "cbs") {
\t \t ps[0].innerHTML = "CBS Radio News<br />1 PM to 3 PM" + cbs;
\t \t set2 = "cbs";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 15 && set2 != "marklevin") {
\t \t ps[0].innerHTML = "Mark Levin Show<br />3 PM" + marklevin;
\t \t set2 = "marklevin";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 16 && set2 != "laura") {
\t \t ps[0].innerHTML = "Laura Ingraham Show<br />4 PM" + laura;
\t \t set2 = "laura";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 17 && set2 != "sean") {
\t \t ps[0].innerHTML = "Sean Hannity Show<br />5 PM" + sean;
\t \t set2 = "sean";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 18 && set2 != "laura") {
\t \t ps[0].innerHTML = "Laura Ingraham Show<br />6 PM" + laura;
\t \t set2 = "laura";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours > 18 && hours < 21 && set2 != "marklevin") {
\t \t ps[0].innerHTML = "Mark Levin Show<br />7 PM to 9 PM" + marklevin;
\t \t set2 = "marklevin";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 21 && set2 != "laura") {
\t \t ps[0].innerHTML = "Laura Ingraham<br />9 PM" + laura;
\t \t set2 = "laura";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 22 && set2 != "sean") {
\t \t ps[0].innerHTML = "Sean Hannity Show<br />10 PM" + sean;
\t \t set2 = "sean";
\t \t div_content = divs[0].innerHTML;
\t \t }
\t if (hours == 23 && set2 != "marklevin") {
\t \t ps[0].innerHTML = "Mark Levin Show<br />11 PM" + marklevin;
\t \t set2 = "marklevin";
\t \t div_content = divs[0].innerHTML;
\t \t }
}
function Control() {
\t just_set = 0
\t if (control == 0 && just_set != 1) {
\t \t divs[0].innerHTML="<p>Paused</p>";
\t \t control = 1;
\t \t just_set = 1
\t }
\t if (control == 1 && just_set != 1) {
\t \t divs[0].innerHTML=div_content;
\t \t just_set = 1;
\t \t control = 0;
\t \t Check()
\t }
}
myVar = setInterval(Check, 1000);
window.i = 0
//alert(window.i)
function buttonFunction() {
\t //alert(window.i);
\t //alert(window.i);
\t if (window.i > 1) {
\t \t //alert(window.i)
\t \t window.i = 0;
\t }
\t if (window.i == 0) {
\t \t var currentdate = new Date();
\t \t hours = currentdate.getHours();
\t \t minutes = currentdate.getMinutes();
\t \t seconds = currentdate.getSeconds();
\t \t days = currentdate.getDay();
\t \t months = currentdate.getMonth();
\t \t years = currentdate.getFullYear();
\t \t years_to_seconds = years * 11404800;
\t \t months_to_seconds = months * 950400;
\t \t days_to_seconds = days * 86400;
\t \t hours_to_seconds = hours * 3600;
\t \t minutes_to_seconds = minutes * 60;
\t \t window.start_time = years_to_seconds + months_to_seconds + days_to_seconds + hours_to_seconds + minutes_to_seconds + seconds;
\t }
\t if (window.i == 1) {
\t \t var currentdate = new Date();
\t \t hours2 = currentdate.getHours();
\t \t minutes2 = currentdate.getMinutes();
\t \t seconds2 = currentdate.getSeconds();
\t \t days2 = currentdate.getDay();
\t \t months2 = currentdate.getMonth();
\t \t years2 = currentdate.getFullYear();
\t \t years_to_seconds2 = years2 * 11404800;
\t \t months_to_seconds2 = months2 * 950400;
\t \t days_to_seconds2 = days2 * 86400;
\t \t hours_to_seconds2 = hours2 * 3600;
\t \t minutes_to_seconds2 = minutes2 * 60;
\t \t end_time = years_to_seconds2 + months_to_seconds + days_to_seconds2 + hours_to_seconds2 + minutes_to_seconds2 + seconds2;
\t \t total_tim = end_time - window.start_time;
\t \t total_time = total_tim.toString();
\t \t alert("It's been " + total_time + " seconds since you hit the button.");
\t \t document.cookie="timeittook=" + total_time;
\t }
\t window.i = window.i + 1;
}
</script>
Кроме того, на странице висело, когда я изменил ссылку на Check() в setInterval команде от Check() для проверки, хотя это правильный синтаксис.
Ваш код слишком длинный. Прочитайте [ask] – Amit
Когда вы проверили код? Вы используете 'document.write' для некоторого вывода, который будет перезаписывать текущую страницу. Кроме того, есть промежуток между 0:00 и 1:00, где он ничего не сделает. – Guffa
Я запустил его в 11 вечера до восьми утра. И когда я говорю, что он «висел», он, как полностью застыл, и маленький пляжный мяч вращался. – ColorCodin