简体   繁体   English

如何使特定的输入触发某些东西?

[英]How do I make a specific input trigger something?

im trying to make a function that checks when a person inputs a number from 0 and 8 and then something happens that corresponds to that number.我正在尝试创建一个函数来检查一个人何时输入了 0 和 8 中的数字,然后发生了与该数字相对应的事情。 For example, the user inputs 5 and this makes it so a picture and text appear and if the person inputs 3 a different picture and text appear and etc.例如,用户输入 5,这使得图片和文字出现,如果人输入 3,则会出现不同的图片和文字等。

So far i have a forum where the person can enter a number but im stuck trying to figure out how to make these inputs trigger the action of show a picture and the text.到目前为止,我有一个论坛,人们可以在其中输入一个数字,但我一直试图弄清楚如何使这些输入触发显示图片和文本的动作。

<div id="Jupiter">
                <div class="pictures" >
                    <img src="img/Jupiter.gif">
                </div>
                    <h1 class="title">Jupiter</h1>
                    <div class="paragraphs"><p> Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a giant planet with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter and Saturn are gas giants; the other two giant planets, Uranus and Neptune, are ice giants. Jupiter has been known to astronomers since antiquity.[17] It is named after the Roman god Jupiter.[18] When viewed from Earth, Jupiter can reach an apparent magnitude of −2.94, bright enough for its reflected light to cast shadows,[19] and making it on average the third-brightest natural object in the night sky after the Moon and Venus. <br><br>Jupiter is primarily composed of hydrogen with a quarter of its mass being helium, though helium comprises only about a tenth of the number of molecules. It may also have a rocky core of heavier elements,[20] but like the other giant planets, Jupiter lacks a well-defined solid surface. Because of its rapid rotation, the planet's shape is that of an oblate spheroid (it has a slight but noticeable bulge around the equator). The outer atmosphere is visibly segregated into several bands at different latitudes, resulting in turbulence and storms along their interacting boundaries. A prominent result is the Great Red Spot, a giant storm that is known to have existed since at least the 17th century when it was first seen by telescope. Surrounding Jupiter is a faint planetary ring system and a powerful magnetosphere. Jupiter has 79 known moons,[21] including the four large Galilean moons discovered by Galileo Galilei in 1610. Ganymede, the largest of these, has a diameter greater than that of the planet Mercury.<br><br>Jupiter has been explored on several occasions by robotic spacecraft, most notably during the early Pioneer and Voyager flyby missions and later by the Galileo orbiter. In late February 2007, Jupiter was visited by the New Horizons probe, which used Jupiter's gravity to increase its speed and bend its trajectory en route to Pluto. The latest probe to visit the planet is Juno, which entered into orbit around Jupiter on July 4, 2016.[22][23] Future targets for exploration in the Jupiter system include the probable ice-covered liquid ocean of its moon Europa.</p>
                </div>
        </div>

So I want it to display this once a person types in the number "5"所以我希望它在一个人输入数字“5”时显示这个

Here's my forum这是我的论坛

<fieldset>
            <legend>Enter a Number between 0 and 9</legend>
            <p>Number: <input type="text" id="inputNumber" placeholder="Number" required></p>
            <p><input type="submit" value="Enter" id="submit" /></p>
        </fieldset>

Here's the script这是脚本

function displayPlanet(){
        var data = getElementbyId("submit").innerHTML;
        if(data == 5){

        }
    }

I understood how to get the function where I'm confused is how exactly do i make the div id Jupiter display.我明白如何获得让我感到困惑的功能是我究竟如何制作 div id Jupiter 显示。 That was my original question, sorry for the misunderstanding.那是我最初的问题,抱歉造成误解。

You can listen to the keyup event from input box.您可以从输入框中收听keyup 事件

 function onKeyUp(e) { if (parseInt(e.value) == 5) { // do something here } }
 <input type="text" onkeyup="onKeyUp(this)">

You need to use DOM你需要使用 DOM

 function action() { var data = document.getElementById("result").innerHTML; //Get the data if (data == 1) { alert("1"); } }
 <input id="result" type="text" onkeyup="action()">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM