&#34;的OnChange&#34; <html:select>字段的功能无效

时间:2016-06-12 16:28:34

标签: javascript html

我的javascript功能不起作用。我的网页上没有任何提醒信息。请帮我... 这是我的Html代码

function checkCompletedProjectStatus() {
  alert("Helloo");
  var dropdownType = document.getElementById("status");
  var current_value = dropdownType.options[dropdownType.selectedIndex].value;
  var dropdown = document.getElementById("extendedHours");
  dropdown[1].style.display = "block";
  dropdown[2].style.display = "block";
  dropdown[3].style.display = "block";
  dropdown[4].style.display = "block";
  dropdown[5].style.display = "block";
  dropdown[6].style.display = "block";
  if (current_value == "Completed") {
    alert("Current Value" + current_value);
    dropdown[1].style.display = "none";
    dropdown[2].style.display = "none";
    dropdown[3].style.display = "none";
    dropdown[5].style.display = "none";
  }
}
<html:select name="status" property="theTasks.status" value="theTasks.status" onchange="checkCompletedProjectStatus(this)">
  <option value="">Select Status</option>
  <option value="Scheduled">Scheduled</option>
  <option value="In progress">In progress</option>
  <option value="Completed">Completed</option>
  <option value="On hold">On hold</option>
  <option value="Extended">Extended</option>
</html:select>

1 个答案:

答案 0 :(得分:0)

以下警告所选值(我删除了未使用的代码)

HTML:

<select id="status" property="theTasks.status" value="theTasks.status" onchange="checkCompletedProjectStatus(this)">
  <option value="">Select Status</option>
  <option value="Scheduled">Scheduled</option>
  <option value="In progress">In progress</option>
  <option value="Completed">Completed</option>
  <option value="On hold">On hold</option>
  <option value="Extended">Extended</option>
<select>

Javascript:

function checkCompletedProjectStatus(target) {
  var dropdownType = document.getElementById("status");
  var current_value = target.value;

  alert('selected value: '+ current_value);

  if (current_value === "Completed") {
    alert("Completed selected");
  }
}