【发布时间】:2015-10-26 23:20:45
【问题描述】:
我在这里遇到了一些麻烦。我正在开发一个按钮,一旦选择该按钮,它将运行一个 JavaScript 函数 - ShowColumn() - 这将使一个表格列出现。表格列首先会被隐藏 - “display:none;” - 但是一旦用户选择按钮,隐藏的表格列就会出现/可见。但是,此表列中将有一个 codeMirror 文本区域。这可以做到吗?如果是这样,有人可以帮忙吗?谢谢:)
我已经包含了我到目前为止所做的事情,如下:
<head>
<style>
.hidden {
display: none;
}
.visible {
display: block;
}
</style>
<script>
function ShowColumn() {
document.getElementById("Column").className = "visible";
}
</script>
<script src="lib/codemirror.js"></script>
<script src="mode/clike/clike.js" type="text/javascript"></script>
<link href="lib/codemirror.css" rel="stylesheet" type="text/css" />
<script src="mode/htmlmixed/htmlmixed.js"></script>
<script src="mode/xml/xml.js"><!-- needed for htmlmixed --></script>
<script src="mode/css/css.js"></script>
<link href="theme/default.css" rel="stylesheet" type="text/css" />
<link href="theme/mdn-like.css" rel="stylesheet" type="text/css" />
<style>
.CodeMirror {
border:none;
width:100%;
height:451px;
margin-left:100;
}
</style>
</head>
<body>
<button onClick="ShowColumn()">Click me</button>
<table>
<tr>
<td>
<textarea id="code2" name="code2" style="padding-top:0px; border:none; padding-left:300px;" >
some css code will be here....
<textarea>
<select style="height:46px; width:100%; margin:0px; position:relative; left:0%;">
<option value="volvo">index.html</option>
<option value="saab">another_page.html</option>
<option value="mercedes">placeholder_page.html</option>
<option value="audi">other.html</option>
</select>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/css",
lineWrapping: true,
theme: 'default',
});
</script>
</td>
<td id="Column" class="hidden">
<textarea id="code2" name="code2" style="padding-top:0px; border:none; padding-left:300px;" >
some css code will be here....
</textarea>
<select style="height:46px; width:100%; margin:0px; position:relative; left:0%;">
<option value="volvo">index.html</option>
<option value="saab">another_page.html</option>
<option value="mercedes">placeholder_page.html</option>
<option value="audi">other.html</option>
</select>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/css",
lineWrapping: true,
theme: 'default',
});
</script>
</td>
<td>
<iframe src="" style="height:550px; width:100%;"></iframe>
</td>
</tr>
</table>
</body>
我做了很多研究,但我没有想出任何解决我问题的方法。这可以单独使用 JavaScript 和 HTML 完成吗?还是我必须将另一种语言合并到系统中才能使隐藏列可见?任何帮助将不胜感激!谢谢
【问题讨论】:
-
jQuery .show() 和 .hide() 效果很好,但我不知道为什么你有什么不起作用?
-
这就是 jQuery、CSS 和 DOM 操作的诞生。
-
您好,感谢您的快速响应:) 什么是 DOM 操作?你能告诉我如何将它合并到我的代码中吗?谢谢大家的帮助!
-
感谢@godmode,每当我使用 jQuery .show() 和/或 .hide() 时,表格列中的内容都会被隐藏,而不是实际的表格列本身。有什么建议?谢谢
标签: javascript html html-table