js控件问题

作者&投稿:鄣菊 (若有异议请与网页底部的电邮联系)
js时间控件~

My97DatePicker,将dateFmt设置为"HH:mm:ss"

效果:

得时间的函数如下

function time(){
now = new Date();
current_weekday=now.getDay();
current_hour=now.getHours();
current_minute=now.getMinutes();
current_second=now.getSeconds();
}

我给你一个原来我做的例子,这个例子里面有你需要的东西。请参考。
这个例子你把他全部复制下来,保存成htm后缀的文件,然后用IE6调试,没有任何问题。他可以动态生成控件,动态调用,动态删除,动态执行你动态生成控件里面的方法。
祝好运
---------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Split BinaryTree Extends</title>
<script language='javascript'>

//全局变量定义:注意所有的层数都是以数组下标的方式对应-------------------------------------
/*定义描述:层id表示方法 ("div_" + 层数[divNumber])
头bool下拉列表id表示方法 ("selectHead_" + 层数[divNumber])
*/

var divNumber = 0; //当前有多少层,0表示第一层,也就是初始的那一层,这里的层指实际的层数
var divLeft = 0; //当前的左边距
var divTop = 0; //当前的上边距
//----------------------------------------------------------------------------------------

function createFirstExpression()//创建第1层,这个方法只有boolSelect_0这个对象用
{
if(divNumber == 0) //如果只有仅仅一层的话,那么建立第二层
{
//创建BoolOption选项第1层
divNumber += 1;
var firstExpressionBoolean = document.createElement("div");
firstExpressionBoolean.id = "div_1";
var selectHead = document.createElement("select");
selectHead.id = "selectHead_1";
var strValue = document.getElementById("boolSelect_0").options[document.getElementById("boolSelect_0").selectedIndex].text;
var opt = new Option(strValue);
selectHead.add(opt);
selectHead.style.setAttribute("position", "absolute"); //绝对于firstExpressionBoolean
selectHead.style.setAttribute("left", "0px");
firstExpressionBoolean.appendChild(selectHead);
firstExpressionBoolean.style.setAttribute("position", "relative");
firstExpressionBoolean.style.setAttribute("top", "5px"); //相对于mainDiv
firstExpressionBoolean.style.setAttribute("left", "-45px"); //相对于mainDiv
firstExpressionBoolean.style.setAttribute("width", "310px");
document.getElementById("mainDiv").appendChild(firstExpressionBoolean);

//创建Condition选项第2层
divNumber += 1;
var secondExpressionCondition = document.createElement("div");
secondExpressionCondition.id = "div_2";
secondExpressionCondition.appendChild(bornCheckBox("2"));
secondExpressionCondition.appendChild(bornTextValue("2"));
secondExpressionCondition.appendChild(bornConditionSelect("2"));
secondExpressionCondition.appendChild(bornBoolSelect("2"));
secondExpressionCondition.style.setAttribute("position", "relative");
secondExpressionCondition.style.setAttribute("top", "30px"); //相对于mainDiv
secondExpressionCondition.style.setAttribute("left", "0px"); //相对于mainDiv
secondExpressionCondition.style.setAttribute("width", "310px");
document.getElementById("mainDiv").appendChild(secondExpressionCondition);

}
else //如果已经创建了3层,那么现在可以开始分离数据,进行树形结构创建
{

createTwoChild(0); //创建三层,插入当前位置
}
}

function bornCheckBox(CurrentDivNumber) //创建复选框,传的是当前要创建的这一层的参数,也就是这一层的参数要赋予值给这个id控件
{
var _checkBox = document.createElement("input");
_checkBox.setAttribute("type", "checkbox");
_checkBox.setAttribute("value", "checked");
_checkBox.style.setAttribute("position", "absolute"); //这个是绝对定位定为于当前层
_checkBox.style.setAttribute("left", "10px");
_checkBox.id = "checkBox_" + CurrentDivNumber;
return _checkBox;
}

function bornTextValue(CurrentDivNumber) //创建Not文本
{
var divTextValue = document.createElement("divTextValue"); //用层定位
divTextValue.id = "divTextValue_" + CurrentDivNumber;
divTextValue.style.setAttribute("position", "absolute"); //这个是绝对定位定为于当前层
divTextValue.style.setAttribute("left", "30px");
var newText= document.createTextNode("not");
divTextValue.appendChild(newText);
return divTextValue;
}

function bornConditionSelect(CurrentDivNumber) //创建条件下拉
{
var conditionSelect = document.createElement("select");
for(var i = 1; i < 6; i++) //只是显示一些数据
{
var opt = new Option("cond" + i);
conditionSelect.add(opt);
}
conditionSelect.style.setAttribute("position", "absolute"); //绝对于当前层
conditionSelect.style.setAttribute("left", "54px");
conditionSelect.style.setAttribute("width", "178px");
conditionSelect.id = "conditionSelect_" + CurrentDivNumber;
return conditionSelect;

}

function bornBoolSelect(CurrentDivNumber) //创建bool下拉
{
var boolSelect = document.createElement("select");
var opt = new Option(" ");
boolSelect.add(opt);
var optAND = new Option("AND");
boolSelect.add(optAND);
var optOR = new Option("OR");
boolSelect.add(optOR);
var optDELETE = new Option("DEL");
boolSelect.add(optDELETE);
boolSelect.style.setAttribute("position", "absolute"); //绝对于当前层
boolSelect.style.setAttribute("left", "245px");
boolSelect.id = "boolSelect_" + CurrentDivNumber;
boolSelect.attachEvent("onchange",function(){createTwoChild(CurrentDivNumber);});
return boolSelect;
}

function bornOnlyOneHeadEX(CurrentDivNumber, InsertLeft, InsertTop, choseNumber) //创建头选项,choseNumber就是你的父行选择的什么选项
{
var selectHeadDiv = document.createElement("div");
var selectHead = document.createElement("select");
var opt = new Option(" ");
selectHead.add(opt);
var optAND = new Option("AND");
selectHead.add(optAND);
var optOR = new Option("OR");
selectHead.add(optOR);
var optDELETE = new Option("DEL");
selectHead.add(optDELETE);
selectHead.style.setAttribute("position", "absolute"); //绝对于当前层
selectHead.style.setAttribute("left", "0px");
selectHead.id = "selectHead_" + CurrentDivNumber;
selectHeadDiv.style.setAttribute();
selectHeadDiv.appendChild(selectHead);
selectHeadDiv.style.setAttribute("position", "relative");
selectHeadDiv.style.setAttribute("top", InsertTop); //相对于mainDiv
selectHeadDiv.style.setAttribute("left", InsertLeft); //相对于mainDiv
selectHeadDiv.style.setAttribute("width", "310px");
selectHead.selectedIndex = choseNumber;
selectHeadDiv.id = "div_" + CurrentDivNumber; //当前层的序号
return selectHeadDiv;
}

function changeAllDivTop(InsertDIVNumber) //插入需要进入的层的位置,也就是说你插入了以后从这个插入层的i+1到Max(i)的所有层增加,这个只控制页面
{
if(InsertDIVNumber < divNumber) //选择的不是最后一行
{
var x = parseInt(divNumber);
var lowerLevel = parseInt(parseInt(InsertDIVNumber) + 1);

for(x=divNumber; x >= lowerLevel; x--)
{
var strTop = document.getElementById("div_" + x).style.top;
var strTopNumber = strTop.substr(0, strTop.length - 2) ;
strTopNumber = 75 + parseInt(strTopNumber);
var currentTop = strTopNumber + "px";
//改变层内的每一个元素的id
if(document.getElementById("div_" + x).childNodes.length == 4)
{
document.getElementById("checkBox_" + x).id = "checkBox_" + (parseInt(x) + 2); //改变check,让他和层标志对应
document.getElementById("divTextValue_" + x).id = "divTextValue_" + (parseInt(x) + 2); //改变not
document.getElementById("conditionSelect_" + x).id = "conditionSelect_" + (parseInt(x) + 2); //改变condSelect
var tempNumber = parseInt(x) + 2;
document.getElementById("boolSelect_" + x).onchange = null;
document.getElementById("boolSelect_" + x).attachEvent("onchange",function(){createTwoChild(tempNumber);}); //修改参数传递
document.getElementById("boolSelect_" + x).id = "boolSelect_" + (parseInt(x) + 2); //改变boolSelect

}
else if(document.getElementById("div_" + x).childNodes.length == 1)
{
document.getElementById("selectHead_" + x).id = "selectHead_" + (parseInt(x) + 2); //改变selectHead
}

//最后来移动层和改变层的标识
document.getElementById("div_" + x).style.top = currentTop;
document.getElementById("div_" + x).id = "div_" + (parseInt(x) + 2); //向下替换层数坐标
}
}
else
{}
}

function createOnlyOneDiv(InsertDIVNumber, InsertLeft, InsertTop) //创建只有一层的check,text,select,相对于MainDiv的left,top
{
var ExpressionCondition = document.createElement("div");
ExpressionCondition.id = "div_" + InsertDIVNumber;
ExpressionCondition.appendChild(bornCheckBox(InsertDIVNumber));
ExpressionCondition.appendChild(bornTextValue(InsertDIVNumber));
ExpressionCondition.appendChild(bornConditionSelect(InsertDIVNumber));
ExpressionCondition.appendChild(bornBoolSelect(InsertDIVNumber));
ExpressionCondition.style.setAttribute("position", "relative");
ExpressionCondition.style.setAttribute("top", InsertTop); //相对于mainDiv
ExpressionCondition.style.setAttribute("left", InsertLeft); //相对于mainDiv
ExpressionCondition.style.setAttribute("width", "310px");
return ExpressionCondition;
}

function createTwoChild(InsertDIVNumber) //创建2个子结点,该子结点又插入的该层位置决定,描述同
{

changeAllDivTop(InsertDIVNumber); //调整下面的位置,多调整2层出来
var parentPureLeft = document.getElementById("div_" + InsertDIVNumber).style.left;//获取插入后,创建三个层里面的中间的一层的left
var parentLeft = parentPureLeft.substr(0, parentPureLeft.length - 2);
var parentPureTop = document.getElementById("div_" + InsertDIVNumber).style.top;//获取插入后,创建三个层里面的中间的一层的top
var parentTop = parentPureTop.substr(0, parentPureTop.length - 2);
var choseNumber = 0;
if(document.getElementById("boolSelect_" + InsertDIVNumber).options[document.getElementById("boolSelect_" + InsertDIVNumber).selectedIndex].text=="AND")
{
choseNumber = 1; //选择的AND选项
}
else
{
choseNumber = 2; //选择的OR选项
}
document.getElementById("mainDiv").removeChild(document.getElementById("div_" + InsertDIVNumber)); //获取完插入这行的信息后,删除该行

//创建子节点
var firstDIV = createOnlyOneDiv(InsertDIVNumber, ((parseInt(parentLeft) + 55)+"px"), (parentTop+"px")); //第一层就是原来的位置
var secondDIV = bornOnlyOneHeadEX((parseInt(InsertDIVNumber) + 1), (parseInt(parentLeft) + 15) + "px", (parseInt(parentTop) + 30)+"px", choseNumber); //第二层bool选项层
var thirdDIV = createOnlyOneDiv((parseInt(InsertDIVNumber) + 2), ((parseInt(parentLeft) + 55)+"px"), (parseInt(parentTop) + 60)+"px");//第三层

document.getElementById("mainDiv").appendChild(firstDIV);
document.getElementById("mainDiv").appendChild(secondDIV);
document.getElementById("mainDiv").appendChild(thirdDIV);

divNumber = parseInt(divNumber ) + 2;
}

</script>
</head>
<body>
<center>
<div id="mainDiv">
<div id="div_0" style="position:relative;left:0px;top:0px;width:310px">
<input type="checkbox" id="checkBox_0" />not

<select id="condSelect_0" style="width:180px">
<option value="0">cond1</option>
<option value="1">cond2</option>
<option value="2">cond3</option>
<option value="3">cond4</option>
<option value="4">cond5</option>
</select>

 

<select id="boolSelect_0" onchange="createFirstExpression()">
<option value=""> </option>
<option value="1">AND</option>
<option value="2">OR </option>
</select>
</div>
</div>
</center>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<script>
function save(obj)
{

alert(obj.value);

}
</script>

<input type="radio" name="<%=i%>" value="a" onClick="save(this)" />111

</BODY>
</HTML>

我这个方法比较简单,应为你没有给出实际的功能需求,我就直接简单点给你了
直接新建html查看里面的效果,观察代码即可

二楼的回答最简单也正确。至于第二个问题js代码中可以运行jsp页面的方法吗?
你说的方法是js方法吧. 如果是js方法肯定是可以的,如果js都在本页面可以相互调用,如果有部分js是在js文件,那么只要在页面引入这个js文件,也是可以调用的。

如果楼上没解决你的问题那么 我再帮忙cpychcpychcpych@yeah.net
功能写详细些

js动态生成的控件,在后台获取不到怎么办
答:1、确定你生成的控件是否在要提交的Form标签内。2、你的控件是否有ID及Name属性。3、确定你后台从Form中获取数据时,Form的Key有没有写错了,最好是观察传过来的所有数据都有些什么,看是否有包含你生成的控件的值。

Asp中添加JS控件问题
答:如果了解这js就放head之间,不了解就扔在body后面。

asp.net 用js获取服务器控件的问题!
答:你肯定是使用了用户控件 你的用户控件名称是 ctl03 在界面获取文本值的时候 需要 用户控件名+“_”+id

如何用JS判断控件是否隐藏
答:用JavaScript隐藏控件的方法有两种,分别是通过设置控件的style的“display”和“visibility”属性。1、当style.display="block"或style.visibility="visible"时控件或见,当style.display="none"或style.visibility="hidden"时控件不可见。不同的是“display”不但隐藏控件,而且被隐藏的控件不再占用显示时...

★☆☆ JS中FOR循坏与表单控件的问题 在线等!
答:同样,要建立一个数组,你需要用以下语句:var c = new Array();js的数组是自动增长的,不需要预分配空间,想在哪里插入就在哪里插入。当然,数组下标不能高于2的32次方。它更像 Java 中的ArrayList而不是数组。下面是我写的一个例子,应该能解答你的问题。把下面的代码粘贴到记事本里面另存为htm...

小程序js怎么给控件设置位置
答:JS设置类名 添加类名或者移除类名来进行实现,在类里面书写控件位置的样式;JS设置style的方式 把控件位置的样式写在style里面 JS设置类名的案例:

autojs找控件慢
答:autojs找控件慢解决方法:1、先停止宏的运行,宏在执行中,引用菜单是灰色的,无法选择。2、在工具菜单中,打开引用。3、打开引用窗口后,在可以用的引用列表中,将有丢失、MISSING、找不到等字样的项目全部取消勾选。4、保存后,正常打开使用即可恢复正常速度。

js datetimepicker控件的时间选择条怎么设置
答:主要体现在bootstrap-datetimepicker控件下面的2个日期参数weekStart: 1, startDate:new Date(日期),引用的基础库有HTML代码复制代码

MVC4的JS控件调用问题
答:从你给的提示可以看出,应该是封装的展现树的控件,首页你的页面需要引用这个js,如何引用我想你应该知道吧,如: 然后假设你那个部门负责人下面的输入框的id为 user ,输入框右侧不是有个图标吗,在图标上加一个onclick事件,如;这里的第一个参数url就是你去后台获取部门负责人的请求连接。第二个参数...

后台传值为空,页面moment.js控件显示为invalid date
答:问题没有说在哪个环境发生的,我就提供一下前端react使用antd传moment时候的置空思路:<MonthPicker locale={locale} className="just_date" format={format} value={text===""||isNaN(text)?null:moment(""+text,format)} onChange={(date,dateString)=>this.editOnChange(record.write...