2014-01-17 37 views
1

我无法从我的下拉菜单中启用选项。由于一些奇怪的原因,我可以禁用,但不能恢复。有没有解决这个问题?我正在使用SharePoint 2007如何从下拉菜单重新启用选项

$(document).ready(function() 
if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']")){ 
$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").attr("disabled", "disabled"); 
} 
else  
if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Resolving']")){ 

$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").removeAttr("disabled"); 
} 
}); 
+2

为什么地球上你有这样的ID? –

回答

3
$("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']") 

是一个jQuery对象,这始终是一个truthy值(即使什么也没有选择)。因此,总是执行第一个if语句。

而是使用$('blah').length来确定是否选择了任何东西。

虽然圣牛,找到一个更好的方式来确定你的DOM。

+0

你说一个有趣的,所以你得到da upvotes – user1596138

+0

这对我来说甚至不好笑我几乎被那个标记冒犯 –

+1

看起来这些ID是动态生成的一个叫做SharePoint的微软软件:) – undefined

0

您错过了ready回调的开头括号。

$(document).ready(function() { <--- here 
    if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Validating']")){ 
     $("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").attr("disabled", "disabled"); 
    } 
    else if($("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Resolving']")){ 
     $("#ctl00_m_g_98b27f90_2d47_4399_9f55_39944c5c3d72_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value='Analysis']").removeAttr("disabled"); 
    } 
}); 
+0

'else'语句是一个'else if'语句哈哈。他不会错过任何东西。 – user1596138

+1

噢,那个换行符是非常误导性的 –

+0

我一开始也很困惑 – user1596138

相关问题