<td width="80"><label>
<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onclick="changeok()"/>
<script type="text/javascript" language="javascript">
var cboxs = document.forms[0].checkbox3;
for(var i=0;i<cboxs.length;i++){
if(cboxs[i].value=="1"){
cboxs[i].checked = true;
}
}
</script>--这是根据数据库该字段值为1就默认选上的JS
</label>
</td>
<td width="121">
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>我的意思就是说查询出来比方有5列,我选第一列的复选框,判断,如过该列复选框选中,那么该行的另一列
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
值默认成当前时间 也不知道说明白没有 FOR循环的不行 我目前唯一迷惑的就是我点第二行,如何取得该行的i值 然后就可以
if(cboxs[i].checked){
alert("wwwwwwwwwwww");
document.forms[0].jhpzyf[i].value = '。';
}
<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onclick="changeok()"/>
<script type="text/javascript" language="javascript">
var cboxs = document.forms[0].checkbox3;
for(var i=0;i<cboxs.length;i++){
if(cboxs[i].value=="1"){
cboxs[i].checked = true;
}
}
</script>--这是根据数据库该字段值为1就默认选上的JS
</label>
</td>
<td width="121">
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>我的意思就是说查询出来比方有5列,我选第一列的复选框,判断,如过该列复选框选中,那么该行的另一列
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
值默认成当前时间 也不知道说明白没有 FOR循环的不行 我目前唯一迷惑的就是我点第二行,如何取得该行的i值 然后就可以
if(cboxs[i].checked){
alert("wwwwwwwwwwww");
document.forms[0].jhpzyf[i].value = '。';
}
解决方案 »
- datetime类型转存为json数据格式后日期的变中文
- jsp 连接数据库sql2000问题
- [求助] ajax的服务器端没有返回值?
- 请教一下list的排序问题
- 正则表达式的问题
- 请问有没有稳定开源的网上商城的源码啊?
- 删除类方法保存后还提示一样的出错,为什么?
- 连接数据库?
- TomCat4.0还是没有解决中文问题。怎么办?请指教……
- No result defined for action and result input
- 急急!异常java.security.InvalidKeyException:No installed provider supports this key
- ActionForward后面4个参数分别代表什么
1。10:00 checkbox 选中
2。11:00 checkbox
3。12:00 checkbox
4。13:00 checkbox
显示时间为11点是这样吗?
如果是这样的话通过循环取i值然后在取document.forms[0].jhpzyf[i+1].value 是不是可以实现呢?
第一行 checkbox 选中 input type="text" 这是数据库里查询出来的时间
第二行 checkbox input type="text"
第三行 checkbox input type="text"
第四行 checkbox input type="text"
这是显示出来的表单
如果
第一行 checkbox 去掉勾选 input type="text" 变成空值
第二行 checkbox 选中 input type="text" 这个值为默认的当前时间
第三行 checkbox input type="text"
第四行 checkbox input type="text"
if(true==checked){
//读取时间innerHTML到input 里面
}else{
//空值'' 到innerHTML input中
}
不知道lz是这个意思么?
第一行 checkbox 选中 input type="text" 这是数据库里查询出来的时间
第二行 checkbox input type="text"
第三行 checkbox input type="text"
第四行 checkbox input type="text"
这是显示出来的表单
其他的checkbox为0或者空,就不默认上,第二列也没有值
如果 我选中第二行的checkbox checked=true 那么input type="text" 值就显示为当前时间 第一行我去掉了勾选,就默认为空,然后我就可以把修改完得再保存到数据库中,这应该说明白了吧第一行 checkbox 去掉勾选 input type="text" 变成空值
第二行 checkbox 选中 input type="text" 这个值为默认的当前时间
第三行 checkbox input type="text"
第四行 checkbox input type="text"
var names = document.getElementsByName(checkbox3);
var len = names.length;
if (len > 0) {
var i = 0;
for (i = 0; i < len; i++)
names[i].checked = true;
}
}
然后oncheck(this.id) 事件中判断当前checkbox是否被选中,如果选中checked设置false,否则就为true这个逻辑你应该明白把?
<input type="checkbox" id="box1" onclick="test(this,'a1');"/> <input id="a1" type="text"/><br/>
<input type="checkbox" id="box2" onclick="test(this,'a2');"/> <input id="a2" type="text"/>function test(check,input_id){
var ipt = document.getElementById(input_id);
if(check.checked){
ipt.value='data'; }else{
ipt.value='';
}
}
<thead>
<tr>
<td width="103" align="center"><div align="center"><strong>任务号</strong></div></td>
<td width="80" align="center"><div align="center"><strong>最终计划标志</strong></div></td>
<td width="121" align="center"><div align="center"><strong>计划确定时间</strong></div></td>
</tr>
</thead>
<tbody>
<logic:notEmpty name="rwresultList">
<logic:iterate id="list" name="rwresultList">
<tr>
<td width="57">
<bean:write name="list" property="id.rwh" />
</td>
<td width="80"><label>
<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onselect="" onclick="changeok()"/>
<script type="text/javascript" language="javascript">
var cboxs = document.forms[0].checkbox3;
for(var i=0;i<cboxs.length;i++){
if(cboxs[i].value=="1"){
cboxs[i].checked = true;
}
}
</script> </label>
</td>
<td width="121">
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
<tbody>
我只写一次CHECKBOX跟INPUT 查询出来5行自动就生成5个 不需要写那么多啊 ID如果我加上的话 应该跟name一样 是相同的 你那个好像不行吧
直接写个onclick="changeok()",changeok()方法不就可以了吗 JAVA实现点东西实在太费劲了
就给你一个js的例子把原理一个样!希望能帮到你·
java实现东西其实不难,只要你把它弄明白了都恨简单
html+js<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function test(check,input_id){
var ipt = document.getElementById(input_id);
if(check.checked){
ipt.value='data'; }else{
ipt.value='';
}
}
function createInput(){
var dv = document.getElementById('div1');
for(var i=0;i<10;i++){
dv.innerHTML+='<input id="a'+i+'" type="text"/><br/>';
}
}
</script>
</head>
<body>
<input type="checkbox" id="box1" onclick="test(this,'a1');"/> <input id="a1" name="an1" type="text"/><br/>
<input type="checkbox" id="box2" onclick="test(this,'a2');"/> <input id="a2" name="an2" type="text"/>
<div id="div1"></div>
<button onclick="createInput();">生成input</button>
</body>
</html>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function test(check,input_id){
var ipt = document.getElementById(input_id);
if(check.checked){
ipt.value='data'; }else{
ipt.value='';
}
}
function createInput(){
var dv = document.getElementById('div1');
for(var i=0;i<10;i++){
dv.innerHTML+="<input type='checkbox' onclick='test(this,\"a"+i+"\");'/><input id='a"+i+"' type='text'/><br/>";
}
}
</script>
</head>
<body> <div id="div1"></div>
<button onclick="createInput();">生成input和checkbox</button>
</body>
</html>你用下·
<thead>
<tr>
<td width="103" align="center"><div align="center"><strong>任务号</strong></div></td>
<td width="80" align="center"><div align="center"><strong>最终计划标志</strong></div></td>
<td width="121" align="center"><div align="center"><strong>计划确定时间</strong></div></td>
</tr>
</thead>
<tbody>
<logic:notEmpty name="rwresultList">
<logic:iterate id="list" name="rwresultList">
<tr>
<td width="57">
<bean:write name="list" property="id.rwh" />
</td>
<td width="80"><label>
<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onselect="" onclick="changeok()"/>
<script type="text/javascript" language="javascript">
var cboxs = document.forms[0].checkbox3;
for(var i=0;i<cboxs.length;i++){
if(cboxs[i].value=="1"){
cboxs[i].checked = true;
}
}
</script> </label>
</td>
<td width="121">
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
<tbody>
我的都直接写完了 不想 动态生成 页面都画完了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function show(obj){
//通过id获取要操作的对象
var tag = obj.id.substr(0,obj.id.indexOf("_")+1);
//通过上述部分id 获得同行的第三列的复选框
var tagCheckBox = document.getElementById(tag+"3_value");
tagCheckBox.value = "2011-07-6";//修改checkBox的value值
var tagCheckText = document.getElementById(tag+"3_text");
tagCheckText.innerText = "2011-07-6";//修改checkBox的文本显示值
}
</script>
</head> <body>
<table>
<tr>
<td>
<input id="r1c_1_value" type="checkbox" value="dd" onmousedown="show(this)"><span id="r1c_1_text">唱歌</span>
</td>
<td>
<input id="r1c_2_value" type="checkbox" value="dd"/><span id="r1c_2_text">音乐</span>
</td>
<td>
<input id="r1c_3_value" type="checkbox" value="dd"/><span id="r1c_3_text">运动</span>
</td>
</tr>
</body>
</html>注意里面之所以用span来将显示文本包含起来是应为input标签是单标记,提示文本不是标签内,故无法通过DOM结构获取,所以将其添加在span中。onmousedown这个可以根据你的情况修改不同的事件,lz看看这个行不?
<script type="text/javascript">
function test(check,input_id){
alert('sdfsdf');
var ipt = document.getElementById(input_id);
if(check.checked){
ipt.value='data'; }else{
ipt.value='';
}
}
</script>
我放弃动态生成,把这段JS放到HEAD里面 <td width="121">
<input id id='a"+i+"' type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>
加上id<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onclick = 'test(this,\"a"+i+"\");'/>
这里加上调用 是这么干吧 可能字符串拼接错误
alert('sdfsdf');
输出不出来
onclick='test(this,\"a"+i+"\");' //这个就是调用test这个函数第一个参数是当前checkbox 第二个是文本框id
<thead>
<tr>
<td width="103" align="center"><div align="center"><strong>任务号</strong></div></td>
<td width="80" align="center"><div align="center"><strong>最终计划标志</strong></div></td>
<td width="121" align="center"><div align="center"><strong>计划确定时间</strong></div></td>
</tr>
</thead>
<tbody>
<logic:notEmpty name="rwresultList">
<logic:iterate id="list" name="rwresultList" indexId="number">
<tr>
<td width="57">
<bean:write name="list" property="id.rwh" />
</td>
<td width="80"><label>
<input type="checkbox" name="checkbox3" value=<bean:write name="list" property="zzjh" /> onselect="" onclick="changeok(<bean:write name="number"/>)"/>
<script type="text/javascript" language="javascript">
var cboxs = document.forms[0].checkbox3;
for(var i=0;i<cboxs.length;i++){
if(cboxs[i].value=="1"){
cboxs[i].checked = true;
}
}
function changeok(num){
var i = num;
var date = new Date(); var cboxs = document.forms[0].checkbox3;
if(cboxs[i].checked){
document.forms[0].jhpzyf[i].value = date.pattern("yyyy-MM-dd HH:mm:ss");
}
else
{
document.forms[0].jhpzyf[i].value = '';
}
</script> </label>
</td>
<td width="121">
<input type="text" width="121" name="jhpzyf" onFocus="c.showMoreDay = false;c.show(this);"/>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
<tbody>