Javascript 使用JS获取文本框的值,然后根据该值将文本输入到其他文本框中

Javascript 使用JS获取文本框的值,然后根据该值将文本输入到其他文本框中,javascript,html,css,text,combobox,Javascript,Html,Css,Text,Combobox,作为大学作业的一部分,我正在创建一个网站,所以我从《大爆炸理论》中选择了一个关于石头、布、剪刀、蜥蜴、斯波克的主题。该网站只需要包含HTML、CSS和JavaScript(因此请不要建议JQuery,因为它不在作业中)。我所有的HTML和CSS都很好,只是我以前没有对JS做太多 我已经创建了一个组合框,有不同的选择,这些是:石头,布,剪刀,蜥蜴和斯波克。 我在页面下面有3个文本框,我已经成功地使用JS从组合框中获取文本值并将其放在中间框中。但我想在第一个框中放当前事物的优势,在第三个框中放当前事

作为大学作业的一部分,我正在创建一个网站,所以我从《大爆炸理论》中选择了一个关于石头、布、剪刀、蜥蜴、斯波克的主题。该网站只需要包含HTML、CSS和JavaScript(因此请不要建议JQuery,因为它不在作业中)。我所有的HTML和CSS都很好,只是我以前没有对JS做太多

我已经创建了一个组合框,有不同的选择,这些是:石头,布,剪刀,蜥蜴和斯波克。 我在页面下面有3个文本框,我已经成功地使用JS从组合框中获取文本值并将其放在中间框中。但我想在第一个框中放当前事物的优势,在第三个框中放当前事物的优势,因此:

如果在组合框中选择了Rock,那么字符串“Rock”将被放置在第二个(中间)框中,因为纸打败了Rock,我希望在第一个框中输入“纸”,因为Rock打败了剪刀,我希望在第三个框中输入“剪刀”

我希望它能根据组合框中所选的值更改为它所击败的和它所击败的

这是我到目前为止得到的,JS是内部的

 <!Doctype html>
<html>

<head>
<link rel="stylesheet" type="text/css"
href="Web.css">
<script>
function Choice()
{
var mylist=document.getElementById("myList");
document.getElementById("Choice").value=mylist.options[mylist.selectedIndex].text;

var x= Choice.value;

}
</script>



</head>
<body> 
<div class="font">
<Div class="Containment">

<div class="Heading">
<h1> A BEGINNERS GUIDE TO 
ROCK-PAPER-SCISSORS-LIZARD-SPOCK  </h1>
</div>
<br>

<diV class="Menu">
<a href="Index.html">The Game</a> | <a href="Rock.html">Rock</a> | <a href="paper.html">paper</a> | <a href="scissors.html">scissors</a> | <a href="Lizard.html">Lizard</a> | <a href="Spock.html">Spock</a>
</diV>
<br>
<img class="centerpic" src="images/rpsls2.Jpg" >
<br>
<center>

<div class="text">
Rock-paper-scissors-lizard-Spock is a five-gesture expansion 
of the classic selection method game rock-paper-scissors. 
It operates on the same basic principle, but includes two additional weapons: 
the lizard (formed by the hand as a sock-puppet-like mouth) 
and Spock (formed by the Star Trek Vulcan salute). 
This reduces the chances of a round ending in a tie.
 The game was invented by <br>
 Sam Kass with Karen Bryla.
 </div>
 </center>

<br>
<center> <iframe width="560" height="315" src="http://www.youtube.com/embed/x5Q6-wMx-K8" frameborder="0" allowfullscreen></iframe> 
<!-- This is the code to place and load my youtube linked video -->
<br>
<br>

<div class="text">

This game is featured numerous times in episodes of the Big Bang Theory and 
is normally used similar to why rock papers scissors is used, to settle indecisions, 
as Sheldon attempts to use it to get the office instead of Barry Kripke in this particular episode.
</div>
</center>
<br>
<br>

<div class="text">
Sign matchups:

Select your symbol of choice:
<select id="myList" onchange="Choice()">
  <option></option>
  <option>Rock</option>
  <option>Paper</option>  
  <option>Scissors</option>
  <option>Lizard</option>
  <option>Spock</option>
</select>
<br>
<br>
<input type="text" id="Wins1" width="10"> Beats
<input type="text" id="Choice" width="10"> Beats
<input type="text" id="Loses1" width="10">
<br>
<br>
<input type="text" id="Wins2" width="10">

<input type="text" id="Loses2" width="10">

<div>
</div>
</body>
</html>

函数选择()
{
var mylist=document.getElementById(“mylist”);
document.getElementById(“Choice”).value=mylist.options[mylist.selectedIndex].text;
var x=选择值;
}
入门指南
石头-布-剪刀-蜥蜴-斯波克

| | | | |

石头剪纸蜥蜴斯波克是一个五姿态的扩展 经典的选择方法游戏石头剪刀布。 它以同样的基本原则运作,但包括两种额外的武器: 蜥蜴(用手做成袜子似的嘴) 斯波克(由《星际迷航》中的瓦肯敬礼组成)。 这降低了一轮以平局结束的机会。 这个游戏是由
山姆·卡斯和凯伦·布莱拉。


这个游戏在《大爆炸理论》和《宇宙大爆炸》中多次出现 通常使用的方式类似于使用石头剪刀来解决犹豫不决, 在这一集中,谢尔顿试图用它来代替巴里·克里普克进入办公室。

签名配对: 选择您选择的符号: 摇滚乐 纸张 剪刀 蜥蜴 斯波克

跳动 跳动

非常感谢您的帮助。 非常感谢和问候,
克里斯

你应该重新命名标题

使用javascript获取下拉列表的值,然后有条件地填充其他输入字段

以下是整个脚本的概念验证:

<script>
function run() {
    var truthTable = up();
    console.log (truthTable);
    //Add a value for each input   
    document.getElementById("srt").value = document.getElementById("Ultra").value;
}

function up() {
        var selectedValue = document.getElementById("srt").value,
        truthTable;
    if(selectedValue === 'rock'){
        //push values based on truth table
    }
    else if (selectedValue === 'paper'){
        //push values based on truth table
        var table = [{ "first":"Paper" , "second":"Rock", "third":"Scissors", "fourth":"Lizard", "fifth":"Spock"}];
    console.log (table);
    return table;

    }
    else if (selectedValue === 'scissors'){
        //push values based on truth table
    }
    else if (selectedValue === 'lizard'){
        //push values based on truth table
    }
    else if (selectedValue === 'spock'){
        //push values based on truth table
    }    

}

</script>

函数运行(){
var truthTable=up();
console.log(truthTable);
//为每个输入添加一个值
document.getElementById(“srt”).value=document.getElementById(“Ultra”).value;
}
函数up(){
var selectedValue=document.getElementById(“srt”).value,
真实的;
如果(selectedValue==='rock'){
//基于真值表推送值
}
else if(selectedValue==‘纸张’){
//基于真值表推送值
var表=[{“第一”:“纸”,“第二”:“石头”,“第三”:“剪刀”,“第四”:“蜥蜴”,“第五”:“斯波克”}];
console.log(表);
返回表;
}
else if(selectedValue===‘剪刀’){
//基于真值表推送值
}
else if(selectedValue===‘蜥蜴’){
//基于真值表推送值
}
else if(selectedValue==='spock'){
//基于真值表推送值
}    
}

只有5种结果

  • 为你的成果建立一个良好的基础

  • 将每个表的数据作为json输入相应的 if语句

  • 返回表作为truthTable变量

  • 迭代数据并将值推送到适当的输入ID

    例如: //为每个输入添加一个值 document.getElementById(“srt”).value=truthTable[0]。value; document.getElementById(“第二个”).value=truthTable.value; document.getElementById(“第三个”).value=truthTable.value; document.getElementById(“第四”).value=truthTable[3]。value; document.getElementById(“第五”).value=truthTable[4]。value

  • 我认为这个例子告诉你该做什么,但也会让你了解你在做什么

    注意:我的示例激发onClick,这不是您案例的触发器,您需要使用其他东西。
    添加了帮助其他有同样问题的人的链接。

    不幸的是,我们只能使用HTML、CSS和Java。如果我能使用JQuery,我会的。有没有办法把它转换成Java呢?答案修改后可以让你了解解决这个问题的一种更直接的方法。我希望你指的是Javascript而不是Java。是的,我指的是Javascript。我将通读你修改过的报告。