Jump to content
HeatoNn

Apelare si afisare in paragraful din pagina mesaj

Recommended Posts

Posted

<html>
<head>
<title> Ora exacta
</title>
<script type="text/javascript" src="exemplu.js"></script>
</head>
<body>
<h1 align="center">Ora exacta in Romania</h1>
<INPUT TYPE="button" name="buton" onclick="scrieText()" value="Afla ora">
</body>
</html>

(aceasta este pagina HTML)

function scrieText()  
{
var timp=13
var time=13
var raspuns=prompt("Ora exacta este?","13");
if (timp < 11)
{
  salut = "Buna dimineata";
}
 else if (time < 18)
{
  salut = "Buna ziua";
}
 else
{
  salut = "Buna seara";
}
}

(aceasta este pagina JS)

Cum fac sa imi afiseze in casuta de sus elementul Salut in functie de if else if si else ?

 

  • Moderators
Posted

Daca vrei sa o afiseze ca pop-up, folosesti alert(). Daca vrei sa o afiseze in pagina, poti declara un div si se agati de el prin innerHTML.

 

<html>
<head>
    <title>Ora exacta</title>
    <script type="text/javascript">
        function scrieText() {
            var timp = 13
            var time = 13
            var raspuns = prompt("Ora exacta este?", "13");
            if (timp < 11) {
                salut = "Buna dimineata";
            } else if (time < 18) {
                salut = "Buna ziua";
            } else {
                salut = "Buna seara";
            }
			document.getElementById('mesaj').innerHTML=salut;
			alert(salut);
        }
    </script>
</head>
<body>
    <h1 align="center">Ora exacta in Romania</h1>
    <input type="button" name="buton" onClick="scrieText()" value="Afla ora">
    <div id="mesaj"></div>
</body>
</html>

 

Posted (edited)
24 minutes ago, Dragos said:

Daca vrei sa o afiseze ca pop-up, folosesti alert(). Daca vrei sa o afiseze in pagina, poti declara un div si se agati de el prin innerHTML.

 

<html>
<head>
    <title>Ora exacta</title>
    <script type="text/javascript">
        function scrieText() {
            var timp = 13
            var time = 13
            var raspuns = prompt("Ora exacta este?", "13");
            if (timp < 11) {
                salut = "Buna dimineata";
            } else if (time < 18) {
                salut = "Buna ziua";
            } else {
                salut = "Buna seara";
            }
			document.getElementById('mesaj').innerHTML=salut;
			alert(salut);
        }
    </script>
</head>
<body>
    <h1 align="center">Ora exacta in Romania</h1>
    <input type="button" name="buton" onClick="scrieText()" value="Afla ora">
    <div id="mesaj"></div>
</body>
</html>

 

Multumesc frumos merge

 

Edited by HeatoNn

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...