【发布时间】:2014-04-08 10:04:25
【问题描述】:
动态创建的表单呈现异常即使禁用了样式表。
表单根据选择的选项显示和隐藏各种详细信息。
因此,例如,以下许多内容将使用 C#.net 呈现...
formOutput += "<div class=\"field textBox\" id=\"" + field.Id + "\"><div class=\"labelTB\"><label for=\"" + field.Id + "\" class=\"" + reqClass + "\">" + field.Name + requirement + "</label></div>" +
"<input type=\"text\" class=\"numInput\" id=\"" + field.Id + "_tb\" name=\"" + field.Name + "\" onkeyup=\"Service.refresh(this); numCheck(this)\" onclick=\"numCheck(this)\" />" +
// numButtons:
"<div class=\"minus plusMinus\" id=\"minus_" + field.Id + "\" onmousedown=\"numBox(this)\" /></div>" +
"<div class=\"plus plusMinus\" id=\"plus_" + field.Id + "\" onmousedown=\"numBox(this)\" /></div></div><br />";
...然后父节点被JS隐藏onload:
var setVisibility = function (id, bool) {
try {
get(id).style.display = (bool) ? "block" : "none";
} catch (e) {
return false;
}
return bool;
}
但是,当有大量隐藏字段时,我的表单中间会出现相当大的空间。
我尝试了各种解决方案,但收效甚微。简单地将所有内容向上移动并不容易(表格比我在这里展示的要复杂得多)......
我什至尝试过以下方法:
var setVisibility = function (id, bool) {
try {
get(id).style.display = (bool) ? "block" : "none";
get(id).style.position = (bool) ? "relative" : "absolute";
get(id).style.height = (bool) ? "auto" : "0px";
var children = get("containerType").childNodes
for (var i in children) {
if (children[i].style) {
children[i].style.display = (bool) ? "block" : "none";
children[i].style.position = (bool) ? "relative" : "absolute";
children[i].style.height = (bool) ? "auto" : "0px";
}
}
} catch (e) {
return false;
}
return bool;
}
是什么导致了这个问题?有解决办法吗?
(见下图)
【问题讨论】:
-
+1 使用油漆 ;)
-
你能发布 URL 或 jsfiddle 的实际代码显示问题
-
您是否尝试过直接通过 CSS 对某些样式进行硬编码。如果这有效,则表明您的 .net 逻辑有问题。或者,它会帮助您构建正确的 CSS 以实现所需的视觉效果。
-
见下面的答案。里面有一个流氓
。我尝试了许多其他解决方案,但收效甚微。
标签: javascript html css .net dom