Javascript 如何选择具有选定值的目标选项

Javascript 如何选择具有选定值的目标选项,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我试图做的是,如果该选项包含此特定文本,它将显示另一个div,但现在我无法仅针对已在其上选择值的选项 如果选项已“选中”,则我希望将其作为目标 不确定这是否是您想要的,请在选择中进行更改 var yourSelectId = document.getElementById("yourselectid"); var option= yourSelectId.options[yourSelectId.selectedIndex].value; if(option == "USD"){ $

我试图做的是,如果该选项包含此特定文本,它将显示另一个div,但现在我无法仅针对已在其上选择值的选项

如果选项已“选中”,则我希望将其作为目标


不确定这是否是您想要的,请在选择中进行更改

var yourSelectId = document.getElementById("yourselectid");


var option= yourSelectId.options[yourSelectId.selectedIndex].value;

if(option == "USD"){
   $('.price.total-rental-price-usd').show();
   $('h3.booking_cost_usd').show();
}

我可能会建议在此下拉列表中使用与更改事件关联的事件侦听器。然后根据所选选项,执行您打算执行的任务

document.getElementById("currencyDropDown").addEventListener('change',
  (event) => {
    switch (event.target.value) {
      case "USD":
        console.log({
          Message: "You have selected USD"
        });
        break;
      case "GBP":
        console.log({
          Message: "You have selected GBP"
        });
        break;
      case "NZD":
        console.log({
          Message: "You have selected NZD"
        });
        break;
    }
  }
);
jsidle:

$(文档).ready(函数(){
var selected_value=$(“#选择器:selected”).val();
如果(所选值=“INR”){
$(“.show_select_value p span”).html(selected_value);
$(“.show_select_value”).show();
}
否则{
$(“.show_select_value p span”).html(“”);
$(“.show_select_value”).hide();
}
})
。显示\u选择\u值{
显示:无;
边框:1px实心#000;
填充:15px;
利润率:20px 0
}

美元
印度卢比
计算机辅助设计
所选值为:

var yourSelectId = document.getElementById("yourselectid");


var option= yourSelectId.options[yourSelectId.selectedIndex].value;

if(option == "USD"){
   $('.price.total-rental-price-usd').show();
   $('h3.booking_cost_usd').show();
}
document.getElementById("currencyDropDown").addEventListener('change',
  (event) => {
    switch (event.target.value) {
      case "USD":
        console.log({
          Message: "You have selected USD"
        });
        break;
      case "GBP":
        console.log({
          Message: "You have selected GBP"
        });
        break;
      case "NZD":
        console.log({
          Message: "You have selected NZD"
        });
        break;
    }
  }
);