简体   繁体   English

同时选择changin

[英]Select changin at the same time

Here is my code 这是我的代码

 <html> <head> <title>Untitled Document</title> </head> <body> <script> function run() { document.getElementById("srt").value = document.getElementById("Ultra").value; } </script> <script> function up() { //if (document.getElementById("srt").value != "") { var dop = document.getElementById("srt").value; //} alert(dop); } </script> <script> function up() { var dop = document.getElementById("srt").value; pop(dop); // Calling function pop } function pop(val) { alert(val); }? </script> <script type language="javascript"> function cargar_imagen(imagen) { var img = document.getElementById("myimage"); var img_dir = "http://silvercowgames.com/ENADRYA/imagenes/cartas"; if (img) { img.src = img_dir + imagen; } } </script> <select name="imagenes" onchange="run();cargar_imagen(this.value)" id="Ultra1"> <option value="">Imagen 1</option> <option value="/Johas/Madriguera-Tolva.jpg" >Imagen 2</option> <option value="/Johas/Coriacia-ancestral.jpg">Imagen 3</option> <option value="4.png">Imagen 4</option> </select> <select id="Ultra"> <!--Call run() function--> <option value="18">Imagen 1</option> <option value="16">Imagen 2</option> <option value="5">Imagen 3</option> <option value="4">Imagen 4</option> </select><br><br> <script> document.getElementById('Ultra1').addEventListener("change", function () { document.getElementById('Ultra').selectedIndex = document.getElementById('Ultra1').selectedIndex; }, false); </script> <img alt src="http://silvercowgames.com/ENADRYA/imagenes/cartas/Johas/Coriacia-ancestral.jpg" id="myimage" align="center"> <br> <form name="frm1"> uno<input type="text" name="uno" id="srt")> </form> </body> </html> 

if you execute that you may see that when you change 1 select the other one changes too but if you change and the go back to the last option the number that is displayed in the txt box change and its not the same. 如果执行该命令,您可能会看到更改1时也选择了另一个更改,但是如果更改并返回到最后一个选项,则txt框中显示的数字将更改,并且该数字不相同。

I need that the numbers match when you change the select option. 当您更改选择选项时,我需要数字匹配。

Please help me 请帮我

Try this 尝试这个

 <script>
    function run() {
        document.getElementById("srt").value = document.getElementById("Ultra").value;
    }
</script>
<script>
    function up() {
        //if (document.getElementById("srt").value != "") {
            var dop = document.getElementById("srt").value;
        //}
        alert(dop);
    }
</script>
<script>
    function up() {
        var dop = document.getElementById("srt").value;
        pop(dop); // Calling function pop
    }

    function pop(val) {
        alert(val);
    }?
</script>
<script type language="javascript">
function cargar_imagen(imagen) {
var img = document.getElementById("myimage");
var img_dir = "http://silvercowgames.com/ENADRYA/imagenes/cartas";
if (img) {
img.src = img_dir + imagen;
}
}
</script>
<select name="imagenes" onchange="" id="Ultra1">
<option value="">Imagen 1</option>
<option value="/Johas/Madriguera-Tolva.jpg" >Imagen 2</option>
<option value="/Johas/Coriacia-ancestral.jpg">Imagen 3</option>
<option value="4.png">Imagen 4</option>
</select>

 <select id="Ultra">  <!--Call run() function-->
     <option value="18">Imagen 1</option>
     <option value="16">Imagen 2</option>
     <option value="5">Imagen 3</option>
     <option value="4">Imagen 4</option>
</select><br><br>
<script>
document.getElementById('Ultra1').addEventListener("change", function () {
    document.getElementById('Ultra').selectedIndex = document.getElementById('Ultra1').selectedIndex;

    run();
    alert(document.getElementById('Ultra').value);
    cargar_imagen(document.getElementById('Ultra1').value)

}, false);
</script>

<img alt src="http://silvercowgames.com/ENADRYA/imagenes/cartas/Johas/Coriacia-ancestral.jpg" id="myimage" align="center">
<br>
<form name="frm1">
uno<input type="text" name="uno" id="srt")>
</form>

Fiddle here 在这里摆弄

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

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