简体   繁体   English

选择选定索引后如何弹出选定警报

[英]How to make selected alert pop up when selected index was choosen

I want to make if selected index in option was choosen then the selected alert is pop up, but I don't know how to do it, here is my JavaScript code: 我想确定是否选择了选项中的选定索引,然后弹出选定警报,但我不知道如何执行,这是我的JavaScript代码:

<script>
    function check1(){
       var e= document.getElementById("maske");
       var selec= e.options[e.selectedIndex].value;
       if(document.selec.value==1){
           alert("Minta tambahan gaji");
       }
    }

My html code: 我的html代码:

<select name="masalah_keuangan" id="maske">
<option value="1">Gaji terlalu sedikit</option>
</select>
<button name="button1" onclick="check1();">Enter</button>

I want if the option value is 1, then the alert("Minta tambahan gaji") pops up 我想如果选项值为1,则弹出alert("Minta tambahan gaji")

How to do it? 怎么做?

Function should be like below 功能应该如下

function check1(){
   var e = document.getElementById("maske");
   var selec = e.options[e.selectedIndex].value;
   if(selec==1){
     alert(e.options[e.selectedIndex].text);
   }
}

First, you need to have to get the value of the option (select) and after the if condition, show the alert: 首先,您需要获取选项的值(选择),然后在if条件之后显示警报:

 function check1(){ var theElement = document.getElementById("maske"); var selectedOption = theElement.options[theElement.selectedIndex].value; if(selectedOption==1){ alert(theElement.options[theElement.selectedIndex].text); } } 
 <select name="masalah_keuangan" id="maske"> <option value="1">Gaji terlalu sedikit</option> <option value="2">Text 2</option> <option value="3">Text 3</option> <option value="4">Text 4</option> </select> <button name="button1" onclick="check1();">Enter</button> 

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

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