javascript更改样式 函数hide() { document.getElementById(“xxx”).style.visibility='visible'; } 655 3338 2013年5月10日 655 3338 2013年5月10日
大家好,我是javascript语言编码方面的新手,我正在开发一个简单的隐藏显示,当你点击表格单元格时,上面的代码(一段代码)就是一个表格2013年5月10日?我的代码中缺少的是,当我再次单击表格单元格时,它将再次隐藏,或返回到默认样式(隐藏或折叠表格)。请重试javascript更改样式 函数hide() { document.getElementById(“xxx”).style.visibility='visible'; } 655 3338 2013年5月10日 655 3338 2013年5月10日,javascript,html,css,Javascript,Html,Css,大家好,我是javascript语言编码方面的新手,我正在开发一个简单的隐藏显示,当你点击表格单元格时,上面的代码(一段代码)就是一个表格2013年5月10日?我的代码中缺少的是,当我再次单击表格单元格时,它将再次隐藏,或返回到默认样式(隐藏或折叠表格)。请重试 <script> function hide() { document.getElementById("xxx").style.visibility='visible'; } <
<script>
function hide()
{
document.getElementById("xxx").style.visibility='visible';
}
</script>
<tr>
<td>655 3338</td>
<td onclick='hide()'>10-May-2013</td>
</tr>
<tr id='xxx' style='visibility:collapse'>
<td>655 3338</td>
<td>10-May-2013</td>
</tr>
演示:试试看
<script>
function hide()
{
document.getElementById("xxx").style.visibility='visible';
}
</script>
<tr>
<td>655 3338</td>
<td onclick='hide()'>10-May-2013</td>
</tr>
<tr id='xxx' style='visibility:collapse'>
<td>655 3338</td>
<td>10-May-2013</td>
</tr>
演示:您最好将行的display属性切换为“none”和“”(空字符串),因为display受到广泛支持,并且似乎更适合这里 e、 g
显示/隐藏下一行
下一排
函数hideNextRow(节点){
//获取父行
var行=最多(节点“tr”);
//如果有,则获取表中的下一行
国际单项体育联合会(世界其他地区){
row=row.parentNode.rows[row.rowIndex+1];
}
//如果有下一行,则根据当前值隐藏或显示该行
//它的style.display属性
国际单项体育联合会(世界其他地区){
row.style.display=row.style.display=='none'?'''none';
}
}
//泛型函数,使用
//标记名的标记名
函数上限(节点、标记名){
var标记名=标记名.toLowerCase();
做{
node=node.parentNode;
}while(node&&node.tagName&&node.tagName.toLowerCase()!=标记名)
//返回匹配的节点,如果未找到,则返回未定义的节点
返回node&&node.tagName&&node.tagName.toLowerCase()==标记名?节点:void 0;
}
您最好将行的display属性切换为“none”和“”(空字符串),因为display受到广泛支持,并且似乎更适合这里
e、 g
显示/隐藏下一行
下一排
函数hideNextRow(节点){
//获取父行
var行=最多(节点“tr”);
//如果有,则获取表中的下一行
国际单项体育联合会(世界其他地区){
row=row.parentNode.rows[row.rowIndex+1];
}
//如果有下一行,则根据当前值隐藏或显示该行
//它的style.display属性
国际单项体育联合会(世界其他地区){
row.style.display=row.style.display=='none'?'''none';
}
}
//泛型函数,使用
//标记名的标记名
函数上限(节点、标记名){
var标记名=标记名.toLowerCase();
做{
node=node.parentNode;
}while(node&&node.tagName&&node.tagName.toLowerCase()!=标记名)
//返回匹配的节点,如果未找到,则返回未定义的节点
返回node&&node.tagName&&node.tagName.toLowerCase()==标记名?节点:void 0;
}
所以诀窍就在这里if(document.getElementById(“xxx”).style.visibility!=“visible”){
谢谢,先生,当我尝试添加两个数字(数字值来自一个文本框
)时,在javascript中为什么要这样做例如,第一个文本框的值是1,另一个是2。答案应该是3,但我的输出是12,thx表示advice@RobertjohnConcpcion因为它进行字符串连接,所以需要首先将它们转换为一个数字,例如:var a='1';var b='2';var c=+a++b;if(document.getElementById(“xxx”)的诀窍就在这里.style.visibility!='visible'){谢谢,先生,当我尝试添加两个数字(数字值来自一个文本框
)时,在javascript中为什么这样做是毫无疑问的例如,第一个文本框的值是1,另一个是2。答案应该是3,但我的输出是12,thx表示advice@RobertjohnConcpcion因为它进行字符串连接,所以需要首先将它们转换为一个数字,例如:var a='1';var b='2';var c=+a++b;
<table>
<tr><td><button onclick="hideNextRow(this);">Show/Hide next row</button>
<tr><td>The next row
</table>
<script>
function hideNextRow(node) {
// Get the parent row
var row = upTo(node, 'tr');
// If there is one, get the next row in the table
if (row) {
row = row.parentNode.rows[row.rowIndex + 1];
}
// If there is a next row, hide or show it depending on the current value
// of its style.display property
if (row) {
row.style.display = row.style.display == 'none'? '' : 'none';
}
}
// Generic function to go up the DOM to the first parent with a
// tagName of tagname
function upTo(node, tagname) {
var tagname = tagname.toLowerCase();
do {
node = node.parentNode;
} while (node && node.tagName && node.tagName.toLowerCase() != tagname)
// Return the matching node or undefined if not found
return node && node.tagName && node.tagName.toLowerCase() == tagname? node : void 0;
}
</script>