js操作table控制tr jquery 两个table左右移动
一.关于动态操作select的问题:
-------------------------------------------------------
//使用json格式传递到前台去
List<String> list = service.loadProvince();
StringBuffer s = new StringBuffer("[");
for(int i = 0 ; i < list.size(); i++){
s.append("\"").append(list.get(i)).append("\"");
if(i<list.size()-1){
s.append(",");
}
}
s.append("]");
//相当于 ["北京","湖南"]
response.setContentType("text/json;charset=UTF-8");
response.getWriter().println(s.toString());
response.getWriter().close();
前台:
<select id="province" onchange="loadCity(this.value);"></select>
var ret = eval("("+responseText+")");
var s = "<option value=''>请选择</option>";
for(var i = 0; i < ret.length;i++){
s +="<option>"+ret[i]+"</option>";
}
document.getElementById("province").innerHTML = s;
前台也可以使用对象方式
var pro = document.getElementById("province");
//先清空
pro.options.length=0;
for(var i = 0; i < ret.length;i++){
var opt = new Option(ret[i]);
pro.options[pro.options.length] = opt;
}
var mySelect = document.createElement("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
var obj=document.getElementById('mySelect');
obj.options.add(new Option("text","value")); //这个兼容IE与firefox
var index=obj.selectedIndex; //序号,取当前选中选项的序号
var val = obj.options[index].value;//读取选定值
var val = obj.options[index].text; //读取选定文本
var val = obj.options[index]=new Option("新文本","新值");//设定新文本
obj.options.remove(index);//删除选中的option
obj.options.length=0;//清除所有option
################################################################################
function ad_changed(obj)
{
id = obj.value;
Ajax.call('adv_auto.php?act=get_id&is_ajax=1', 'parent_id='+id, re_ad_changed, "GET", "JSON");
}
function re_ad_changed(result)
{
child = document.getElementById('ad_id');
child.options.length=0;
for(i = 0; i < result.content.length; i++)
{
child.options.add(new Option());
child.options[i].value = result.content[i].ad_id;
child.options[i].text = result.content[i].ad_name;
}
child.style.display = "";
return ;
}
############################################################################
var text = "test";
var params_select = document.getElementById("params_select");
//创建标签
var opt = document.createElement("option");
//创建文本
var _text = document.createTextNode(text);
//把文本赋给标签
opt.appendChild(_text);
//属性赋值
opt.setAttribute("value",objs[m].keyid);
opt.setAttribute("selected","selected");
//添加
params_select.appendChild(opt);
###########################################################################
javascript动态创建Option选项,选择月份后动态创建日期。
<html>
<head>
<title>javascripttest</title>
<script type="text/javascript">
function setDay()
{
var themonth=document.getElementById("month");
var themaxmonthday=31;
if(themonth.value=="2")
{
themaxmonthday=28;
}
var theday=document.getElementById("day");
var tempdaylength=theday.options.length;
for(var j=tempdaylength;j>0;j--)
{
theday.options.remove(j);
}
for(var i=1;i<=themaxmonthday;i++)
{
var theOption=document.createElement("option");
theOption.innerHTML=i+"日";
theOption.value=i;
theday.appendChild(theOption);
}
}
</s