<body><SCRIPT LANGUAGE="JavaScript">
<!--
var s = '<table border="1" width="100%" height="100%"><tr><td> </td></tr><tr><td height="50"> </td></tr></table>';
var div = document.createElement("DIV");
div.id = "mm";
div.innerHTML = s;
div.style.backgroundColor="yellow"; //position你自己加
document.body.appendChild(div);
//-->
</SCRIPT>
<!--
var s = '<table border="1" width="100%" height="100%"><tr><td> </td></tr><tr><td height="50"> </td></tr></table>';
var div = document.createElement("DIV");
div.id = "mm";
div.innerHTML = s;
div.style.backgroundColor="yellow"; //position你自己加
document.body.appendChild(div);
//-->
</SCRIPT>
解决方案 »
- 请教个问题,百度异步统计代码为什么要求放在head前面,如果不这么做有什么问题
- js实现动态卷角翻页
- 将可执行程序exe,改成使用浏览器浏览
- jquery实现图片提示效果,鼠标移动到图片上市tooltip,求教大虾!!
- 文本的宽度怎么调不了JS里面
- 用js操纵过vml的请帮忙,如何读写v:PolyLine的points?
- 帮忙看看这个简单的表格
- 急:请问我想使iframe的高度等于iframe里连接的页面的高度,代码怎么写么?
- javascript中如何获知一个table的高度?
- 请问如何动态获得浏览器的高度?
- 求正则,防止多位数字重复的
- ■■100分,各位帮忙看看,难啊■■我想获取一个TD在页面中坐标,为什么总是不准,而且和鼠标所在的坐标不一样。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title>
<script language="javascript">
var beginMoving=false;
function MouseDownToMove(obj){
obj.style.zIndex=1;
obj.mouseDownY=event.clientY;
obj.mouseDownX=event.clientX;
beginMoving=true;
obj.setCapture();
}function MouseMoveToMove(obj){
if(!beginMoving) return false;
obj.style.top = (event.clientY-obj.mouseDownY);
obj.style.left = (event.clientX-obj.mouseDownX);
}
function MouseUpToMove(obj){
if(!beginMoving) return false;
obj.releaseCapture();
obj.style.top=0;
obj.style.left=0;
obj.style.zIndex=0;
beginMoving=false;
var tempTop=event.clientY-obj.mouseDownY;
var tempRowIndex=(tempTop-tempTop%25)/25;
if(tempRowIndex+obj.rowIndex <0 )tempRowIndex=-1;
else tempRowIndex=tempRowIndex+obj.rowIndex;
if(tempRowIndex >= obj.parentElement.rows.length-1) tempRowIndex = obj.parentElement.rows.length-1;
obj.parentElement.moveRow(obj.rowIndex,tempRowIndex);
}</script>
</head>
<body >
用鼠标移动TR<br>
<TABLE WIDTH="300" BORDER="1" >
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD bgcolor=blue>0</TD><TD>0</TD><TD>0</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD bgcolor=black>1</TD><TD>1</TD><TD>1</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD bgcolor=red>2</TD><TD>2</TD><TD>2</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD>3</TD><TD>3</TD><TD>3</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD>4</TD><TD>4</TD><TD>4</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD>5</TD><TD>5</TD><TD>5</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD>6</TD><TD>6</TD><TD>6</TD></TR>
<TR bgcolor=#ffffff style='height:25;position:relative;' onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);'><TD>7</TD><TD>7</TD><TD>7</TD></TR> </script>
</TABLE> </body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title><style>
TD,INPUT{ font-size:12; }
</style>
</head><body bgcolor=EEEEEE>
<form name="frm" action="about:结果页面" method=post >
<h4 align=center>JK的动态明细示例</h4><table align="center" bordercolor=cccccc border=1 width=100% >
<tr>
<td width=500>
</td>
<td align=right>
<input type="button" value="增加" class="bottom" onclick="addDetailProcess();">
<input type="button" value="删除" class="bottom" onclick="delDetailProcess();">
<input type="button" value="完成" class="bottom" onclick="submitProcess();">
</td>
</tr>
</table>
<div width=100% id=thedetailtableDIV>
<table align="center" bordercolor=cccccc border=1 width=100% >
<tr bgcolor=eeeeee id="trDetailTitles">
<td ><input type=checkbox onclick="selectallcheckbox(this)"></td>
<td >明细ID*</td>
<td >明细NAME</td>
</tr>
<tbody id="tbDetailUsed" >
<tr>
<td ><input type="checkbox" name="record_select" ></td>
<td ><input type="text" name="detail_id" value='' ></td>
<td ><input type="text" name="detail_name" value='' ></td>
</tr> <tr height=0 ><td colspan=100 height=0 > 合计</td></tr>
</tbody> </table>
</div>
</form><!--复制的内容-->
<table id="tbDetailPrepare" style="display:none">
<tr>
<td ><input type="checkbox" name="record_select" ></td>
<td ><input type="text" name="detail_id" value='' ></td>
<td ><input type="text" name="detail_name" value='' ></td>
</tr>
</table>
<input name="theHistoryRecord" type=hidden value="">
</body></html><script language=javascript> window.onload = historyOncemore;
window.onbeforeunload = fixHistory; function fixHistory() //记住历史
{
document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
} function historyOncemore() //恢复历史
{
if (document.all("theHistoryRecord").value!="")
{document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
}
} function selectallcheckbox(obj) //全选或全不选
{
var tureorfalse=obj.checked;
var theDetail=tbDetailUsed.rows;
for(var i=0;i<theDetail.length-1;i++)
{
theDetail[i].all("record_select").checked=tureorfalse;
}
}
function addDetailProcess(afterRowIndex) //增加明细
{
var alltbDetailUsed= document.all("tbDetailUsed").rows;
var theFirstSelectedDetail;
if (afterRowIndex==null)
{
theFirstSelectedDetail=alltbDetailUsed.length-2;
}
else theFirstSelectedDetail=afterRowIndex;
var newRow = document.all("tbDetailPrepare").rows[0].cloneNode(true);
var desRow = alltbDetailUsed[theFirstSelectedDetail+1];
desRow.parentElement.insertBefore(newRow,desRow ); }
function delDetailProcess() //删除明细
{
var alltbDetailUsed= document.all("tbDetailUsed").rows;
if (confirm("确定选择正确并且要将这些明细删除")==false) return false;
for(var i=0;i<alltbDetailUsed.length-1;i++)
{
if (alltbDetailUsed[i].all("record_select").checked==true)
{
document.all("tbDetailUsed").deleteRow(i);
i=i-1;
}
}
} function submitProcess()
{
document.frm.submit();
}
</script>
你想要的,可能是这个:<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page Selection</title>
<style>
td{white-space:nowrap};
body{margin-left:0;margin-right:0;margin-top=0;margin-bottom=0};
</style>
</head><body bgcolor=eeeeee><table>
<tr >
<td>
<select name=SrcSelect size=6 style="font-size:11pt;width=200;height=160px" multiple >
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
<option value="6">test6</option>
</select>
</td>
<td align="center">
<input align="left" type=button value="→" onclick="moveLeftOrRight(document.all.SrcSelect,document.all.ObjSelect)" ><br><br>
<input align="left" type=button value="←" onclick="moveLeftOrRight(document.all.ObjSelect,document.all.SrcSelect)" >
</td>
<td>
<select name=ObjSelect size=6 style="font-size:11pt;width=200;height=160px" multiple >
<option value="11">test11</option>
<option value="12">test12</option>
<option value="13">test13</option>
<option value="14">test14</option>
<option value="15">test15</option>
<option value="16">test16</option>
</select>
</td>
<td>
<input type=button value="↑" onclick="moveUp()" ><br><br>
<input type=button value="↓" onclick="moveDown()" >
</td>
</tr>
</table>
</body>
<script language=javascript>
function moveUp()
{
var theObj=document.all.ObjSelect;
for(var i=1;i<theObj.length;i++)
{
if( theObj.options[i].selected && !theObj.options[i-1].selected )
{
theObj.options[i].swapNode(theObj.options[i-1]);
}
}
}
function moveDown()
{
var theObj=document.all.ObjSelect;
for(var i=theObj.length-2;i>-1;i--)
{
if( theObj.options[i].selected && !theObj.options[i+1].selected )
{
theObj.options[i].swapNode(theObj.options[i+1]);
}
}
}
function moveLeftOrRight(fromObj,toObj)
{
var lengthOfToObj=toObj.length;
for(var i=fromObj.length-1;i>-1;i--)
{
if(fromObj.options[i].selected)
{
toObj.add(new Option(fromObj.options[i].text,fromObj.options[i].value),lengthOfToObj);
toObj.options[lengthOfToObj].selected=true;
fromObj.options[i].removeNode(true);
}
}
}
</script>
search Div Or CreatecreateElement and so on!
我用了你的方法,创建成功了,但是这个DIV不能拖动,只是追加在页面的最底部了。我是这样改的,不知道哪里错了
function CreatObject(){
var s = '<table border="1" width="100%" height="100%"><tr><td> </td></tr><tr><td height="50"> </td></tr></table>';
var div = document.createElement("DIV");
div.innerHTML = s;
div.style.backgroundColor="yellow"; //position你自己加
div.style.position="absolute";
div.onmousedown="moveit(this)";
document.body.appendChild(div);
}
<script language=javascript>
function add()
{
var sj;
time=new Date();
sj=time.getMilliseconds();
var div=document.createElement("DIV");
div.id="div"+sj;
div.innerHTML="<table border=1 align=center id='tb"+sj+"'><tr><td>"+sj+"</td></tr></table>";
div.style.backgroundColor="green";
div.onmousedown="moveit(this)";
div.contentEditable=true
document.body.appendChild(div);
}
</script>
contentEditable=true
<input type="button" value="增加" name="B3" onclick="add()">
<script language=javascript>
function add()
{
var sj;
time=new Date();
sj=time.getMilliseconds();
var div=document.createElement("DIV");
div.id="div"+sj;
div.innerHTML="<table border=1 align=center id='tb"+sj+"' bgcolor=red width='100%'><tr><td>"+sj+"</td></tr></table>";
div.style.backgroundColor="green";
div.contentEditable=true
document.body.appendChild(div);
}
</script>
<div onMouseDown="function1()"></div>
<script language=javascript>
function add()
{
var obj=document.createElement("<input type='hidden'>");
document.body.appendChild(obj);
}
</script>
奇怪了!!!
<input type="button" value="增加" name="B3" onclick="add()">
<script language=javascript>
function add()
{
var sj;
time=new Date();
sj=time.getMilliseconds();
var div=document.createElement("DIV");
div.id="div"+sj;
div.innerHTML="<table border=1 align=center id='tb"+sj+"' bgcolor=red width='100%'><tr><td>"+sj+"</td></tr></table>";
div.style.backgroundColor="green";
div.contentEditable=true
document.body.appendChild(div);
}function document.onmousedown()
{
if(event.srcElement.tagName=="DIV")
alert(event.srcElement.id);
}
</script>
function add()
{
sj=new Date();
var obj=document.createElement("INPUT");
obj.type="hidden";
obj.id="hd";
document.body.appendChild(obj);
hd.value=sj.getMilliseconds();
alert(hd.value)
}
</script>
<input type="button" value="test" name="B3" onclick="add()">
</body>
<SCRIPT LANGUAGE="JavaScript" defer>
<!--
var s = '<div onclick="alert(11)" style="background-color:red;"><table border="1" width="100%" height="100%"><tr><td> </td></tr><tr><td height="50"> </td></tr></table></div>';document.body.insertAdjacentHTML("beforeEnd",s);
//-->
</SCRIPT>
document.body.appendChild(obj);
是加在页面最后,如果页面有2 个table,要加在2
个table中间怎么办?
document.body.appendChild(obj);
是加在页面最后,如果页面有2 个table,要加在2
个table中间怎么办?
document.all.table1.appendChild(obj);
个table中间怎么办?
table2.parentNode.insertBefore(div, table2);