JS 点击表格改变input的值

puhjack 2011-12-14 04:37:56
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv = "Content-type" content = "text/html; charset = gb2312">
<title>date selector</title>
<style type = "text/css" charset = "gb2312">
<!--
.change
{
background-color: red;
}
table
{
width: 183px;
height: 10px;
}
table tr
{
height: 10px;
font-size: 13px;
color: blue;
text-align: center;
}
.arrowSize
{
font-size: 7px;
}
.dateSize
{
font-size: 12px;
}
-->
</style>
</head>
<body>
<script>
<!--
var year = 2011;
var month = 12;
var date = 1;
var lastDay = new Date(year, month, 0);
lastDay = lastDay.getDate();
var firstDay = new Date(year, month-1, 1);
firstDay = firstDay.getDay();


var print = "";
var count = 0;
var weekNum = ['日', '一', '二', '三', '四', '五', '六' ];
print += "<table>";
print += "<tr>";
print += "<td><<</td>";
print += "<td><</td>";
print += "<td>2011年12月31日</td>";
print += "<td>></td>";
print += "<td>>></td>";
print += "</tr>";
print += "</table>";
print += "<table>";
print += "<tr height = \"20\">";
for( var iWeek = 0; iWeek < 7; iWeek++ )
{
print += "<td>"+weekNum[iWeek]+"</td>";
}
print += "</tr>";

for( var iRow = 0; iRow < 6; iRow++ )
{
print += "<tr>";
for( var iCol = 0; iCol < 7; iCol++ )
{
var value = count++;
if( count < 32 )
{
print += "<td onmouseover=this.className='change' onmouseout=this.className='' onclick = \"writeValue( "+this.count+" );\" />"+(value+1);
print += "</td>";
// print += "<td onmouseover=this.className='change' onmouseout=this.className='' onclick = \"alert("+count+");\">"+count; // alert("+count+");
}
}
print += "</tr>";
}
print += "</table>";
print += "<table><td><input style = \"text\" id = \"getInput\" value = "+this.date+"></td></table>";
document.write( print );

function writeValue( countTrans )
{
代码想在这里实现。
}

-->
</script>
</body>
</html>


运行后我想将传输的值填入绘制的input标签的value中。
简单点就是改变input框内的值。
...全文
261 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
_懒猫 2011-12-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 huzhe419 的回复:]

引用 5 楼 angun123 的回复:

从3楼看出lz不适合编程~~~,还百思不得其解
吓得我都不敢问问题。。
[/Quote]
5楼的意思是:不懂就不要问。。。
huzhe419 2011-12-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 angun123 的回复:]

从3楼看出lz不适合编程~~~,还百思不得其解
[/Quote]吓得我都不敢问问题。。
puhjack 2011-12-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 angun123 的回复:]
从3楼看出lz不适合编程~~~,还百思不得其解
[/Quote]
呵呵,貌似你是一开始就能熟练操作这些。
puhjack 2011-12-15
  • 打赏
  • 举报
回复
你不理我我就不结贴,嘿嘿
zhouyusunquan 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 angun123 的回复:]

从3楼看出lz不适合编程~~~,还百思不得其解
[/Quote]
楼上这位,这是你片片么
angun123 2011-12-15
  • 打赏
  • 举报
回复
从3楼看出lz不适合编程~~~,还百思不得其解
puhjack 2011-12-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 p2227 的回复:]
又是你啊,js基础还要加强,看看dom吧

http://www.w3school.com.cn/htmldom/index.asp


HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<h……
[/Quote]

我先开始这么写
function writeValue( countTrans )
{
var getPut = document.getElementById( 'getInput' ).value;
getPut = countTrans;
// 但是不能成功,百思不得其解。
}
p2227大哥留个联系方式呗,现在有点崇拜你咯。
hjack315@sina.com
121467359
kkjjww 2011-12-14
  • 打赏
  • 举报
回复
function writeValue( countTrans )
{
//代码想在这里实现。
document.getElementById("getInput").value=countTrans;
}
p2227 2011-12-14
  • 打赏
  • 举报
回复
又是你啊,js基础还要加强,看看dom吧

http://www.w3school.com.cn/htmldom/index.asp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv = "Content-type" content = "text/html; charset = gb2312">
<title>date selector</title>
<style type = "text/css" charset = "gb2312">
<!--
.change
{
background-color: red;
}
table
{
width: 183px;
height: 10px;
}
table tr
{
height: 10px;
font-size: 13px;
color: blue;
text-align: center;
}
.arrowSize
{
font-size: 7px;
}
.dateSize
{
font-size: 12px;
}
-->
</style>
</head>
<body>
<script>
<!--
var year = 2011;
var month = 12;
var date = 1;
var lastDay = new Date(year, month, 0);
lastDay = lastDay.getDate();
var firstDay = new Date(year, month-1, 1);
firstDay = firstDay.getDay();


var print = "";
var count = 0;
var weekNum = ['日', '一', '二', '三', '四', '五', '六' ];
print += "<table>";
print += "<tr>";
print += "<td><<</td>";
print += "<td><</td>";
print += "<td>2011年12月31日</td>";
print += "<td>></td>";
print += "<td>>></td>";
print += "</tr>";
print += "</table>";
print += "<table>";
print += "<tr height = \"20\">";
for( var iWeek = 0; iWeek < 7; iWeek++ )
{
print += "<td>"+weekNum[iWeek]+"</td>";
}
print += "</tr>";

for( var iRow = 0; iRow < 6; iRow++ )
{
print += "<tr>";
for( var iCol = 0; iCol < 7; iCol++ )
{
var value = count++;
if( count < 32 )
{
print += "<td onmouseover=this.className='change' onmouseout=this.className='' onclick = \"writeValue( "+this.count+" );\" />"+(value+1);
print += "</td>";
// print += "<td onmouseover=this.className='change' onmouseout=this.className='' onclick = \"alert("+count+");\">"+count; // alert("+count+");
}
}
print += "</tr>";
}
print += "</table>";
print += "<table><td><input style = \"text\" id = \"getInput\" value = "+this.date+"></td></table>";
document.write( print );

function writeValue( countTrans )
{
document.getElementById("getInput").value = countTrans;
}

-->
</script>
</body>
</html>

87,914

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧