刚刚被领导逼着弄公司里的嵌入式WEB维护,现在在自学javascript,
解决方案 »
- javascript定义的function中有五个参数,调用时只输两个可以吗
- 求助正则表达式的用法
- 来者有分,用过dtree的请进,如何增加和删除菜单项,在线急等!
- 日期比较问题,急....
- jquery的jquery.validate库小问题请教大家感谢了!
- 如何用网页中的脚本处理post方式提交的数据?什么脚本都行!
- 问一个问题,检查选项后,为什么不显示层呀?
- js复选框传值的问题?
- 怎样用javaScript计算两个日期字符串相差的天数?
- 我觉得研究诸如jQuery源码这种事情,有个最大的问题在里面。
- jquery.pagination 无刷新分页请求2次
- 为什么获取table的直接后代标签对象(childNods)第一个会是3#text??
刚刚不小心按到了ENTER键,问题没说完就发布了,现在我的代码如下
<!DOCTYPE html>
<html>
<head>
<title>this is a test web</title>
</head>
<body><h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
<tr>
<th>时间</th>
<th>设备</th>
<th>事项</th>
</tr>
<tr>
<td>2013-09-09</td>
<td>rtu</td>
<td>reboot</td>
</tr></table>
<!-- This is a comment start -->
<script type="text/javascript">
<!--
document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
//-->
</script><!-- This is a comment end -->
<input type="button" value="读取" onclick="setTd()">
</body>
</html>
专家们能知道一下吗?为什么我的按钮点击时无效呢
2.按钮点击无效,是因为onclick="setTd()" setTd这个方法没有修改如下:使用IE,点击读取,rtu这个位置会更新为2013-08-08<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>this is a test web</title>
</head>
<body><h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
<tr>
<th>时间</th>
<th>设备</th>
<th>事项</th>
</tr>
<tr>
<td>2013-09-09</td>
<td>rtu</td>
<td>reboot</td>
</tr></table>
<!-- This is a comment start -->
<script type="text/javascript">
<!--
function setTd(){
document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
}
//-->
</script><!-- This is a comment end -->
<input type="button" value="读取" onclick="setTd()">
</body>
</html>
刚刚不小心按到了ENTER键,问题没说完就发布了,现在我的代码如下
<!DOCTYPE html>
<html>
<head>
<title>this is a test web</title>
</head>
<body><h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
<tr>
<th>时间</th>
<th>设备</th>
<th>事项</th>
</tr>
<tr>
<td>2013-09-09</td>
<td>rtu</td>
<td>reboot</td>
</tr></table>
<!-- This is a comment start -->
<script type="text/javascript">
<!--
document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
//-->
</script><!-- This is a comment end -->
<input type="button" value="读取" onclick="setTd()">
</body>
</html>
专家们能知道一下吗?为什么我的按钮点击时无效呢
JS代码没有写在function里。LZ的写法是页面加载时执行。要使点击生效,应该写functionfunction setTd() {
document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
}
<html>
<head>
<title>this is a test web</title>
</head>
<body>
<h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
<tr>
<th>时间</th>
<th>设备</th>
<th>事项</th>
</tr>
<tr>
<td>2013-09-09</td>
<td>rtu</td>
<td>reboot</td>
</tr>
</table>
<!-- This is a comment start -->
<script type="text/javascript">
<!--
var setTd = function(){
document.getElementById('table1').rows[1].cells[0].innerHTML="2013-08-08";
}
//-->
</script>
<!-- This is a comment end -->
<input type="button" value="读取" onclick="setTd()">
</body>
</html>参考下
大侠,你执行后是可以的吗,能介个图给我看看啊,我这里怎么测试不行啊,而且现在还是乱码,我这个是在IE里执行的哦因為我加了<meta http-equiv="content-type" content="text/html; charset=utf-8">
去掉就可以了。,不過樓上已經給出方案,用row[1]代替row(0)可以兼容不同瀏覽器了。