JavaScript総合:表を描く、セルを結合する、右クリックメニュー、モードウィンドウ、バブルウィンドウ
index.
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title> </title>
- <!-- -->
- <script>
- //
- function showDialog1(){
- omenu.style.left = -100;
- omenu.style.top = -100;
- var ijson = window.showModalDialog(' .html',window,'dialogWidth:400px;dialogHeight:400px');
- var oimg = document.createElement("img");
- oimg.inum=ijson.inum;
- oimg.iname=ijson.iname;
- if(ijson.itype=="1"){
- oimg.itype=" ";
- oimg.src="img/ .jpg";
- }
- else if(ijson.itype=="2"){
- oimg.itype=" ";
- oimg.src="img/ .jpg";
- }
- else if(ijson.itype=="3"){
- oimg.itype=" ";
- oimg.src="img/ .jpg";
- }
- oimg.imoney=ijson.imoney;
- oimg.title=" :"+oimg.inum+"
"+" :"+oimg.iname+"
"+" :"+oimg.itype+"
"+" :"+oimg.imoney+"
";
- objTD.appendChild(oimg);
- objTD.leftclick="false";
- }
- //
- function showDialog2(){
- omenu.style.left = -100;
- omenu.style.top = -100;
- var ijson = window.showModalDialog(' .html',objTD,'dialogWidth:400px;dialogHeight:400px');
- objTD.childNodes[0].inum=ijson.inum;
- objTD.childNodes[0].iname=ijson.iname;
- objTD.childNodes[0].itype=ijson.itype;
- objTD.childNodes[0].imoney=ijson.imoney;
- objTD.childNodes[0].title=" :"+objTD.childNodes[0].inum+"
"+" :"+objTD.childNodes[0].iname+"
"+" :"+objTD.childNodes[0].itype+"
"+" :"+objTD.childNodes[0].imoney+"
";
- }
- //
- function showDialog3(){
- omenu.style.left = -100;
- omenu.style.top = -100;
- var formula = window.showModalDialog(' .html',window,'dialogWidth:400px;dialogHeight:400px');
- if(formula!=""){
- document.getElementById("formula").innerHTML=" :"+formula;
- objTD.childNodes[0].imoney = (eval(formula.replace(/a/,objTD.childNodes[0].imoney)));
- objTD.childNodes[0].title=" :"+objTD.childNodes[0].inum+"
"+" :"+objTD.childNodes[0].iname+"
"+" :"+objTD.childNodes[0].itype+"
"+" :"+objTD.childNodes[0].imoney+"
";
- }
- }
- //
- function del(){
- objTD.removeChild(objTD.childNodes[0]);
- objTD.rightclick="true";
- objTD.leftclick="true";
- objTD.style.backgroundColor="";
- }
- //
- function rent(){
- omenu.style.left = -100;
- omenu.style.top = -100;
- objTD.style.backgroundColor='#999999';
- objTD.leftclick="false";
- }
-
- //
- function draw(){
- if(document.getElementById("rowNum").value==""){
- alert(" !");
- return false;
- }
- else if(isNaN(document.getElementById("rowNum").value)){
- alert(" !");
- return false;
- }
- else if(document.getElementById("colNum").value==""){
- alert(" !");
- return false;
- }
- else if(isNaN(document.getElementById("colNum").value)){
- alert(" !");
- return false;
- }
- var row=document.getElementById("rowNum").value;
- var col=document.getElementById("colNum").value;
- s="<table id='table1' border='1' cellpadding='0' cellspacing='0' ";
- s+="style='border-collapse:collapse' oncontextmenu=window.event.returnValue=false>";
- for(var i=0;i<row;i++){
- ss=s+"<tr>";
- for(var j=0;j<col;j++){
- ss=s+"<td onclick='fun_onclick(this);' onmousedown='showMenu(this);'style='width:50px; height:50px' rightclick='true' leftclick='true'></td>";
- }
- ss=s+"</tr>";
- }
- ss=s+"</table>";
- tables.innerHTML=s;
- }
-
- var x1;
- var x2;
- var first = true;
- var objTD;
- var omenu;
- //
- function fun_
- if(obj.leftclick=="true"){
- if(first){
- first = false;
- x1=obj;
- }
- else{
- first = true;
- x2=obj;
- }
- obj.style.backgroundColor='#0000ff';
- obj.rightclick = "false";
- }
- }
-
- function rebulid(){
- //
- x1.style.border="0";
- x2.style.border="0";
- }
-
- //
- function showMenu(obj){
- omenu = document.getElementById("main_menu");
- if(window.event.button == 2 && obj.rightclick=="true"){
- objobjTD = obj;
- omenu.style.left = event.x;
- omenu.style.top = event.y;
- }
- else{
- omenu.style.left = -100;
- omenu.style.top = -100;
- }
- }
-
- </script>
- </head>
- <body>
-
- <div >
- :<input id="rowNum" type="text"/>
- :<input id="colNum" type="text"/>
- <input id="Button1" type="button" value=" " onclick="draw()" />
- <input id="Button2" type="button" value=" " onclick="rebulid()" />
- </div>
- <div id="formula" ></div>
- <br/>
-
- <span id="tables"></span>
- <div id="main_menu"
- style="position:absolute; background-color:#999999; left:-100px; top:-100px; width:80px; height:200px;">
- <div onClick="showDialog1()"> </div>
- <br />
- <div onClick="showDialog2()"> </div>
- <br />
- <div onClick="del()"> </div>
- <br />
- <div onClick="showDialog3()"> </div>
- <br />
- <div onClick="rent()"> </div>
- </div>
- <div>
- <img title="123" style="position:absolute;left:-100px; top:-100px"/>
- </div>
- </body>
- </html>
作成.
- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title> </title>
- <script language="javascript" type="text/javascript">
- function fun1()
- {
- var ijson = {};
- ijson.inum = document.form1.inum.value;
- ijson.iname = document.form1.iname.value;
- ijson.itype = document.getElementById("itype").value;
- ijson.imoney = document.form1.imoney.value;
- parent.window.returnValue=ijson; //
- window.close();
- }
- </script>
- </head>
-
- <body>
- <form name="form1" action="" >
- :<input type="text" name="inum"/><br />
- :<input type="text" name="iname"/><br />
- :<select id="itype" >
- <option value="0" >--- ---</option>
- <option value="1" > </option>
- <option value="2" > </option>
- <option value="3" > </option>
- </select><br />
- :<input type="text" name="imoney"/><br />
- <input id="Button1" type="button" value=" " onclick="fun1();"/>
- <input id="Button2" type="button" value=" " onclick="window.close();" />
- </form>
- </body>
- </html>
編集.
- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title> </title>
- <script>
- window.onload=function(){
- var txts = document.getElementsByTagName("input");
- txts[0].value=window.dialogArguments.childNodes[0].inum;
- txts[1].value=window.dialogArguments.childNodes[0].iname;
- txts[2].value=window.dialogArguments.childNodes[0].itype;
- txts[3].value=window.dialogArguments.childNodes[0].imoney;
- }
- function fun1(){
- var ijson = {};
- ijson.inum = document.form1.inum.value;
- ijson.iname = document.form1.iname.value;
- ijson.itype = document.form1.itype.value;
- ijson.imoney = document.form1.imoney.value;
- parent.window.returnValue=ijson; //
- window.close();
- }
- </script>
- </head>
-
- <body>
- <form name="form1" action="" >
- :<input name="inum" type="text" readonly="true" onclick="alert(' ');"/><br />
- :<input name="iname" type="text" /><br />
- :<input name="itype" type="text" /><br />
- :<input name="imoney" type="text" /><br />
- <input id="Button1" type="button" value=" " onclick="fun1();"/>
- <input id="Button2" type="button" value=" " onclick="window.close();" />
- </form>
- </body>
- </html>
設定.
- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title> </title>
- <script language="javascript" type="text/javascript">
- function fun1()
- {
- var formula = document.form1.formula.value;
- parent.window.returnValue=formula; //
- window.close();
- }
- </script>
- </head>
-
- <body>
- <form name="form1" action="">
- :<input type="text" name="formula"><br />
- <input id="Button1" type="button" value=" " onclick="fun1();" />
- <input id="Button2" type="button" value=" " onclick="window.close();" />
- </form>
- </body>
- </html>