我有此刻的Chrome存在的问题奇特工作......这就是我要完成的:的JavaScript string.search无法在Chrome
我有一系列的桌子部分,其中已经确定的与它们的ID因此,像这样的:
T = Tab
G = Group within Tab
S = Sub-Group within Group
# = Numerical index
for example:
<tr id="T1"> = Tab 1
<td id="T1G3"> = Tab 1 , Group 3
<td id="T1G3S1"> = Tab 1, Group 3, Sub-Group 1
漂亮的直线前进那么远,使用JavaScript的帮助下,我还旨在激活或关闭这些团体的形式。现在,这是我遇到的问题...当我的表单加载第一次时,我想要禁用窗体上的所有需要它的东西。为此,我创建了一个动态函数,可以为我实现这一点,我将指定哪些标记受到影响,以及在这些标记的ID内查找哪些内容,如果匹配发生,请禁用它,如下所示:
Pseudo and Definition:
Function DisableAll(string TagNamesCSArray, string RegExpContent)
{
Split the tag names provided into an array
- loop through the array and get all tags using document.getElementsByTagName() within page
-- if tags are found
--- loop through collection of tags/elements found
---- if the ID of the element is present, and MATCHES the RegExp in any way
----- disable that item
---- end if
--- end loop
-- end if
- end loop
}
,这是非常容易实现,这是最终的结果:
function DisableAll(TagNames, RegExpStr)
{
//declare local vars
var tagarr = TagNames.split(",");
var collection1;
var IdReg = new RegExp(RegExpStr);
var i;
//loop through getting all the tags
for (i = 0; i < tagarr.length; i++)
{
collection1 = document.getElementsByTagName(tagarr[i].toString())
//loop through the collection of items found, if found
if (collection1)
{
for (y = 0; y < collection1.length; y++)
{
if (collection1[y].getAttribute("id") != null)
{
if (collection1[y].getAttribute("id").toString().search(IdReg) != -1)
{
collection1[y].disabled = true;
}
}
}
}
}
return;
}
然后我打电话的地方,它是这样的:
DisableAll("tr,td", "^T|^T[0-9]S");
看起来很简单是吗? “Hannnn!”错误的答案蝙蝠侠......这工作完美,在所有浏览器中,除了Chrome ...现在为什么呢?我不明白。也许我的RegExp有问题?
任何帮助将不胜感激。
干杯!
MaxOvrdrv
谢谢...当你回应了这个,我刚刚得知IE禁用元素不同于其他浏览器...例如:我需要禁用匹配的ID内的控件,而不是具有匹配的ID的控件......伤心......因为这样做在执行这样的任务时非常有用......:S – MaxOvrdrv 2012-04-16 18:54:53