Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   div.innerHTML почему не работает в верху (https://javascript.ru/forum/events/83532-div-innerhtml-pochemu-ne-rabotaet-v-verkhu.html)

ksa 05.01.2022 14:05

Цитата:

Сообщение от leon2009sp (Сообщение 542765)
const day = (new Date()).getDay();
            let html = '<p>INFORMATION</p>';
            if (day == 1) html = '1.dat';
			if (day == 2) html = '2.dat';			
			if (day == 3) html = '3.dat'; 
			if (day == 4) html = '4.dat';
			if (day == 5) html = '5.dat';
			if (day == 6) html = '6.dat';
			if (day == 7) html = '7.dat';
//...

так правильно???

Хорош индусить. :nono:
const day = (new Date()).getDay();
let html = '<p>INFORMATION</p>';
if (day) html = day + '.dat';
alert(html)

leon2009sp 05.01.2022 19:47

может кому пригодиться
 
<script language="JavaScript">
                  nowDate=new Date();
                  theDay=nowDate.getDay();
                  text=new Array(30);
                  text[0]="7777777";
                  text[1]="11111111";
                  text[2]="2222222";
                  text[3]="3333333";
                  text[4]="4444444";
                  text[5]="555555555";
                  text[6]="66666666666";
                  document.write(text[theDay]);
                  </script>

может кому пригодиться document.write:victory:

ksa 05.01.2022 20:46

Цитата:

Сообщение от leon2009sp
text=new Array(30)

30 дней недели? :blink:

leon2009sp 06.01.2022 09:48

на хостинге не работает
 
на денвере работает :dance:
а на хостинг закачиваю и приехали :-?
window.addEventListener('DOMContentLoaded', function()
          {
 const day = (new Date()).getDay();
            let html = '<p>0000000</p>';
			if (day) html = day + '.dat';            
			if (!day || day == 4) info = html;		  
function get_file(url, callback)
{
	xmlhttp=new XMLHttpRequest();
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function()
{
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
	callback(xmlhttp.responseText);
}
}
xmlhttp.send();
}
get_file(info, function(response) 
{
document.getElementById("output").innerHTML=response
})		  
 }		  
);

это я пробовал и так и так ее :-E а она ни в какую
просто вывод текста то работает, а из файлов тока на локалке

leon2009sp 06.01.2022 09:54

ага понял почему: 1.txt читает, а вот если расширение *.dat = то на сервере прочитать не может.

leon2009sp 08.01.2022 21:22

ам, не работает воскресенье
 
window.addEventListener('DOMContentLoaded', function()
          {
            const day = (new Date()).getDay();
            let html = '<p>INFORMATION</p>';
			if (day) html = day +'.txt';			
			readTextFile(html);
          }
        );

не работает когда воскресенье

leon2009sp 08.01.2022 21:58

не фуричит с воскресеньем
 
function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
				document.getElementById("output").innerHTML=allText;
                
            }
        }
    }
    rawFile.send(null);
}
window.addEventListener('DOMContentLoaded', function()
          {
            const day = (new Date()).getDay();
            let html = '<p>INFORMATION</p>';
			if (day) html = readTextFile('admin/text/week/' + day + '.txt');
			readTextFile(html);
          }
        );

leon2009sp 08.01.2022 22:08

как правильно вписать скрипт? сюда?
window.addEventListener('DOMContentLoaded', function()
		{
}

этот скрипт:
ball.onmousedown = function(event)
{
let shiftX = event.clientX - ball.getBoundingClientRect().left;
let shiftY = event.clientY - ball.getBoundingClientRect().top;
ball.style.position = 'absolute';
ball.style.zIndex = 1000;
document.body.append(ball);
moveAt(event.pageX, event.pageY);
function moveAt(pageX, pageY) 
{
ball.style.left = pageX - shiftX + 'px';
ball.style.top = pageY - shiftY + 'px';
};
function onMouseMove(event)
{
 moveAt(event.pageX, event.pageY);
};
document.addEventListener('mousemove', onMouseMove);
ball.onmouseup = function()
{
document.removeEventListener('mousemove', onMouseMove);
ball.onmouseup = null;
};
};
ball.ondragstart = function()
{
return false;
};

если скрипт движения картинки установить наверх то картинка перестает двигаться.

leon2009sp 29.01.2022 15:46

т.е. я понимаю что нужно дождаться загрузки скрипта: но как я вставляю сюда
window.addEventListener('DOMContentLoaded', function()
скрипт все перестает работать. т.е. window.addEventListener -> дожидается когда загрузиться страница, но не когда я нажму на мышку.


Часовой пояс GMT +3, время: 07:46.