js 동적 생산 table, Div, select
<!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>js </title>
<script language="javascript">
/* , appendChild*/
function init(){
_table=document.getElementById("table");
_table.border="1px";
_table.width="800px";
for(var i=1;i<10;i++){
var row=document.createElement("tr");
row.id=i;
for(var j=1;j<6;j++){
var cell=document.createElement("td");
cell.id=i+"/"+j;
cell.appendChild(document.createTextNode(" "+cell.id+" "));
row.appendChild(cell);
}
document.getElementById("newbody").appendChild(row);
}
}
function rebulid(){
var beginRow=document.getElementById("beginRow").value;/* */
var endRow=document.getElementById("endRow").value;/* */
var beginCol=document.getElementById("beginCol").value;/* */
var endCol=document.getElementById("endCol").value;/* */
var tempCol=beginRow+"/"+beginCol;/* */
alert(tempCol);
var td=document.getElementById(tempCol);
/* */
for(var x=beginRow;x<=endRow;x++){
for(var i=beginCol;i<=endCol;i++){
if(x==beginRow){
document.getElementById("table").rows[x].deleteCell(i+1);
}
else{
document.getElementById("table").rows[x].deleteCell(i);
}
}
}
td.rowSpan=(endRow-beginRow)+1;
}
/* , appendChild */
function addRow(){
var length=document.getElementById("table").rows.length;
/*document.getElementById("newbody").insertRow(length);
document.getElementById(length+1).setAttribute("id",length+2);*/
var tr=document.createElement("tr");
tr.id=length+1;
var td=document.createElement("td");
for(i=1;i<4;i++){
td.id=tr.id+"/"+i;
td.appendChild(document.createTextNode(" "+td.id+" "));
tr.appendChild(td);
}
document.getElementById("newbody").appendChild(tr);
}
function addRow_withInsert(){
var row=document.getElementById("table").insertRow(document.getElementById("table").rows.length);
var rowCount=document.getElementById("table").rows.length;
var countCell=document.getElementById("table").rows.item(0).cells.length;
for(var i=0;i<countCell;i++){
var cell=row.insertCell(i);
cell.innerHTML=" "+(rowCount)+"/"+(i+1)+" ";
cell.id=(rowCount)+"/"+(i+1);
}
}
/* , deleteRow(row Index)*/
function removeRow(){
/* var row=document.getElementById("2");
var index=row.rowIndex;
alert(index);*/
document.getElementById("newbody").deleteRow(document.getElementById(document.getElementById("table").rows.length).rowIndex);
}
/* , insertCell( ) */
function addCell(){
/*document.getElementById("table").rows.item(0).cells.length
*/
for(var i=0;i<document.getElementById("table").rows.length;i++){
var cell=document.getElementById("table").rows[i].insertCell(2);
cell.innerHTML=" "+(i+1)+"/"+3+" ";
}
}
/* , deleteCell( ) */
function removeCell(){
for(var i=0;i<document.getElementById("table").rows.length;i++){
document.getElementById("table").rows[i].deleteCell(0);
}
}
</script>
</head>
<body onLoad="init();">
<table id="table" align="center">
<tbody id="newbody"></tbody>
</table>
<div>
<table width="800px" border="1px" align="center">
<tr><td align="center"><input type="button" id="addRow" name="addRow" onClick="addRow();" value=" "/></td><td align="center"><input type="button" id="delRow" name="delRow" onClick="removeRow();" value=" "/></td></tr>
<tr><td align="center"><input type="button" id="delCell" name="delCell" onClick="removeCell();" value=" "/></td><td align="center"><input type="button" id="addCell" name="addCell" onClick=" addCell();" value=" "/></td></tr>
<tr><td align="center" colspan="2"><input type="button" id="addRows" name="addRows" onClick="addRow_withInsert();" value=" "/></td></tr>
</table>
</div>
<div>
<table width="800px" border="1px" align="center">
<tr><td> <input type="text" id="beginRow" name="beginRow" value=""/> <input type="text" name="endRow" id="endRow" value=""/> </td><td rowspan="2" id="test"><input type="button" name="hebing" id="hebing" value=" " onClick="rebulid();"/></td></tr>
<tr><td> <input type="text" name="beginCol" id="beginCol" value=""/> <input type="text" name="endCol" id="endCol" value=""/> </td></tr>
</table>
</div>
</body>
</html>
두 번 째:
<html>
<head><title>aa</title>
<script src="jquery.js"></script>
<script>
var abc={'class': 'newDivClass', id: 'newDiv', name: 'newDivName'};
alert(abc["class"]);
function aaa()// DIV
{
var newElement = document.createElement('div');
var newText = document.createTextNode(' div 。');
document.getElementById("mydiv").appendChild(newElement); // ,
newElement.id = 'newDiv';
newElement.className = 'newDivClass';
newElement.setAttribute('name ','newDivName');
newElement.style.width = '300px';
newElement.style.height = '200px';
newElement.style.margin = '0 auto';
newElement.style.border = '1px solid #DDD';
newElement.appendChild(newText);
}
//$(function(){alert("asdf");});
var i=0;
function clickme()// TABLE
{
i++;
var tbl=document.getElementById("tb");
var row=tbl.insertRow(tbl.rows.length);
var cell1=row.insertCell(row.cells.length);
var cell2=row.insertCell(row.cells.length);
var cell3=row.insertCell(row.cells.length);
var cell4=row.insertCell(row.cells.length);
cell1.innerHTML="a"+i;
cell2.innerHTML="b"+i;
cell3.innerHTML="c"+i;
cell4.innerHTML="<a href='javascript:deleteRow("+(tbl.rows.length-1)+")'>delete</a>";
cell1.setAttribute("width","150px");
cell2.setAttribute("width","150px");
cell3.setAttribute("width","150px");
cell4.setAttribute("width","150px");
//row.style.setAttribute("backgroundColor","#e0e0e0");
row.style["backgroundColor"]="#e0e0e0"; //
tbl.style.setAttribute("backgroundColor","olive");
tbl.setAttribute("width","500px");
//alert(row.style["backgroundColor"]);
}
function leo()//
{
var tbl=document.getElementById("tb");
for(var k=0;k<tbl.rows.length;k++)
{
tbl.rows[k].cells[3].innerHTML="<a href='javascript:deleteRow("+k+")'>delete</a>";
}
}
function deleteRow(obj)//
{
var tbl=document.getElementById("tb");
tbl.deleteRow(obj);
leo();
}
function clickme2()//
{
var my=document.getElementById("mydiv");
//alert(my);
my.innerHTML=$("#mydiv").html()+"<div style='border-bottom:1px solid purple'>zhaosheng</div>";
//my.appendChild("<div style='border:1px solid purple'>zhaosheng</div>");
}
var k=0;
function createSelect()// SELECT、
{
document.getElementById("sel").options[document.getElementById("sel").options.length] = new Option("optionName"+k,"optionValue"+k);
k++;
}
function change(obj)//select change function
{
alert(obj.value);
}
function common(type,attr,style,html)
{
var element=document.createElement(type);
document.body.appendChild(element);
for(var k in attr)
{
element.setAttribute(k,attr[k]);
}
for(var k in style)
{
element.style[k]=style[k];
}
element.appendChild(document.createTextNode(html));
}
function commontest()
{
var attr={"name":"myname","id":"myid"};
var style={"width":"500px","height":"400px","border":"1px solid purple"};
var html="this is my text";
common("div",attr,style,html);
}
</script>
</head>
<body>
<a href="javascript:commontest();">commontest</a>
<a href="javascript:aaa();">aaa</a>
<a href="javascript:clickme();">clickme</a>
<table id="tb">
<tr>
<td>id</td>
<td>name</td>
<td>age</td>
<td>operate</td>
</tr>
</table>
<a href="javascript:clickme2();">clickme2</a>
<div style="border:1px solid olive;padding:5px 0px 10px 3px" id="mydiv"></div>
<a href="javascript:createSelect();">createSelect</a>
<select id="sel" onchange="javascript:change(this);">
</select>
</body>
</html>
세 번 째:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="product_list.aspx.cs" Inherits="LanChuang.MemWeb.scm.member.center.Product" %>
<html>
<head runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript" type="text/javascript">
<!--
function insertTable() {
var table = document.all['ListTable'];
//
var objRow = table.insertRow();
objRow.height = 22;
objRow.bgColor = "#ffffff";
objRow.align = 'center';
objRow.onmousedown = function() { GetRow(this); };
//
var objCel = objRow.insertCell(0);
objCel.align = 'center';
objCel.innerHTML = 1;
objCel.style.setAttribute("border-bottom","#000000 2px solid");
objCel.style.setAttribute("border-right","#000000 2px solid");
//
var objCel = objRow.insertCell(1);
objCel.align = 'center';
objCel.innerHTML = "<input type='hidden' name='ProdId' id='ProdId_1' value='1'/>SP00000781";
//
var objCel = objRow.insertCell(2);
objCel.align = 'left';
objCel.innerHTML = " ";
//
var objCel = objRow.insertCell(3);
objCel.align = 'center';
objCel.innerHTML = " ";
//
var objCel = objRow.insertCell(4);
objCel.align = 'right';
objCel.innerHTML = "<input name='proNum' maxlength='12' id='proNum_1' type='text' size='8' class='input2' value='1.00' isNull='false' dataType='number' onblur='calculateNumber(this)'/>";
//
var objCel = objRow.insertCell(5);
objCel.align = 'right';
objCel.innerHTML = "100";
}
function GetRow(src) {
alert(src.rowIndex);
}
//-->
</script>
</head>
<body id="body">
<table bordercolor="#000000" id="ListTable" width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;border-top: #000000 2px solid; border-left: #000000 2px solid; border-bottom: #000000 1px solid">
<tr>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;" width="30">NO</td>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;" width="100"> </td>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;"> </td>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;" width="100"> </td>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;" width="100"> </td>
<td align="center" style="border-right: #000000 1px solid; border-bottom: #000000 1px solid;" width="120"> </td>
</tr>
</table>
<input type="button" onclick="insertTable()" value=" ">
</body>
</html>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
기초 정리 - 1문자 (String) 숫자 (Number) 불린 (Boolean) null undefined 심볼 (Symbol) 큰정수 (BigInt) 따옴표로 묶어 있어야 함 Not-A-Number - 숫자 데이터 / 숫자로 표...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.