根据选择显示其他内容

时间:2009-06-10 06:53:43

标签: javascript html conditional

Is this also the Risk Address:
<select name="InsuredSALicense2" id="InsuredSALicense2">
  <option>Please Select</option>
  <option>Yes</option>
  <option>No</option>
</select> 

如果此处的答案为“否”,则必须创建隐藏的下拉列表。

If No, Please give details: 
<textarea name="InsuredOther License2" 
          id="InsuredOther License2" 
          cols="30" rows="4"></textarea>
<form id="form4" name="form4" method="post" action="">

在表单上说我要创建一个下拉列表(例如:“你......”,请选择是/否):如果答案为“是”,则删除一个部分,如果没有那么不要t下拉部分。

此表单在Dreamweaver cs4中完成。

3 个答案:

答案 0 :(得分:1)

你可以相对容易地做到这一点。使用javascript框架jQuery,您可以执行以下操作:

/* Attach an event to your dropdown menu containing Yes/No */
$("#InsuredSALicense2").change(function(){
  /* Check Value After Change */
  if (this.val() == "Yes") {
    /* Show the dropdown field */
    $("#hiddenDIV").show();
  } else {
    /* Hide the dropdown field */
    $("#hiddenDIV").hide();
  }
});

此示例假设您的“隐藏”下拉列表位于名为“hiddenDIV”的内容中:

<div id="hiddenDIV">
  <p>Hidden drop down stuff here</p>
</div>

要使用此代码示例,您需要从标记中引用jQuery库。

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>

答案 1 :(得分:0)

你是ASP.net中的wrokin吗? 如果您在ASP.net中工作..您可以在Dropdownlist文本更改事件中创建隐藏的下拉列表...首先,您可以检查所选下拉列表的值是什么... 如果您有任何问题,请告诉我

答案 2 :(得分:0)

我认为一个好的解决方案是在客户端做:所以生成textarea和下拉菜单。隐藏不是默认值的那个(例如,style =“visibility:hidden”)。然后在InsuredSALicense2列表框上创建一个onchange事件,该列表框隐藏不重要的字段并显示重要字段。

相关问题