基于组合框隐藏和禁用元素';用JavaScript实现s值
我有一个页面,根据组合框的值是否为false(否),应该隐藏基于组合框隐藏和禁用元素';用JavaScript实现s值,javascript,html,Javascript,Html,我有一个页面,根据组合框的值是否为false(否),应该隐藏输入框,并禁用字段集。当组合框的值更改为true(yes)时,表单应显示输入框并启用字段集 for(var i = 0; i < input.length; i++) { if(boolHide){ input[i].setAttribute("disabled", "disabled");
输入
框,并禁用字段集
。当组合框的值更改为true(yes)时,表单应显示输入
框并启用字段集
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
这就是我到目前为止所做的:
<html>
<head>
<title>combo</title>
<script language="javascript">
function ToggleDisplay(Section, boolHide) {
if (boolHide == true) {
Section.style.display = "none";
}
else {
Section.style.display = "";
}
}
function disableElement(element, boolHide)
{
var input =
document.getElementById(element).getElementsByTagName("input");
for(var i = 0; i < input.length; i++)
{
input[i].setAttribute("disabled",boolHide);
}
}
function hideShowElement(CurrentSection, OtherSection, DisableSection)
{
var sectionVal = CurrentSection.value;
if (sectionVal == 0) {
ToggleDisplay(OtherSection, true);
//disableGroup (this.form, 'Radio1' , true);
disableElement(DisableSection, "true");
}
else {
ToggleDisplay(OtherSection, false);
//disableGroup (this.form, 'Radio1' , true);
disableElement(DisableSection, "false");
}
}
</script>
</head>
<body>
<form name="testForm" action="" method="post">
Show Hidden Text? <select name="cmbYN"
onchange="hideShowElement(this, MyDIV, 'OptionGrp1');">
<option value="0" selected="selected"></option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<div id="MyDIV" style="display: none">
My Hidden Text: <input name="Text1" type="text" />
<br>
</div>
<fieldset id="OptionGrp1" name="Group1">
Option Group<br><br>
Option 1<input name="Radio1" type="radio" checked>
Option 2<input name="Radio1" type="radio">
</fieldset>
</form>
</body>
</html>
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
联合体
功能切换显示(区域,后台){
if(boolHide==true){
Section.style.display=“无”;
}
否则{
Section.style.display=“”;
}
}
功能禁用元素(元素,后台)
{
变量输入=
document.getElementById(element.getElementsByTagName(“输入”);
对于(变量i=0;i
选项组
选择1
选择2
这将隐藏
输入
框并禁用字段集
,但不会重新启用它们。您应该将显示更改回以前的状态,通常是阻塞
if (boolHide){
Section.style.display = "none";
}else {
Section.style.display = "block";
}
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
对于残疾人,正确的方法是将disabled属性设置为disabled,然后将其删除:
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
for(变量i=0;i
您应该将显示改回原来的状态,通常是块显示
if (boolHide){
Section.style.display = "none";
}else {
Section.style.display = "block";
}
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
对于残疾人,正确的方法是将disabled属性设置为disabled,然后将其删除:
for(var i = 0; i < input.length; i++)
{
if(boolHide){
input[i].setAttribute("disabled", "disabled");
}else{
input[i].removeAttribute("disabled");
}
}
for(变量i=0;i
就个人而言,我喜欢添加/删除类(如“隐藏”),因为这样可以解决在更改样式之前必须弄清楚样式的棘手问题。对于一个类,您可以将表示(即隐藏/不隐藏)留给CSS。但是请注意,您不能使用CSS启用/禁用。我个人喜欢添加/删除一个类(如“隐藏”),因为这样可以避免在更改样式之前必须弄清楚样式是什么这一棘手问题。对于一个类,您可以将表示(即隐藏/不隐藏)留给CSS。但是请注意,您不能使用CSS启用/禁用。还有一点,一般认为布尔值不会像这样进行测试。只需使用if(boolHide)
或if(!boolHide)
Yes true,该死的复制粘贴:)我还更改了答案,以正确回答禁用的部分。还有一点,一般认为布尔值不会这样测试。只需使用if(boolHide)
或if(!boolHide)
Yes true,该死的复制粘贴:)我还更改了答案以正确回答禁用部分。