[問題] javascript動態生成button
我利用生成子節點的觀念去做
但button 我還是不會做,指點一下吧
我附上我的程式碼
------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>下拉式選單節點</title>
<style>
.menutitle {
font-family:新細明體;font-size:20;width:100;
height:14;
background-color:#88FFFF;
position:absolute;top:150;
}
.menu {border:groove 3px;
font-family:新細明體;font-size:18;width:240;
height:14;
background-color:#44eeee;
position:absolute;
top:150;
visibility:hidden;
}
</style>
</head>
<body onmouseover="hidemenu();" bgcolor="#BBFFFF">
<p><font color="#0000FF" size="5" face="全真綜藝體">下拉式選單的節點
</font></p>
<p>子節點內容:<input type="text" id=t1 size="20" ></p>
<input type="button" size="12" value="新增子節點" onclick="append_node();">
<hr>
<span id=mt1 class="menutitle" style="left:10;z-index:2"
onmouseover="showmenu();">
test<br>
</span>
<span id=m1 class="menu" style="left:10;z-index:3" onmouseover="showmenu();">
test<br>
<FORM >
<INPUT TYPE="button" value='Sports' ><br>
<INPUT TYPE="button" value='Heath' ><br>
<INPUT TYPE="button" value='Finance' ><br>
</span></FORM>
<script language="javascript">
//新增子節點的函數
function append_node(){
var tnode1,tnode2,tnodebr;
tnode1=document.createElement('INPUT TYPE=button');
tnodebr=document.createElement("br");
m1.appendChild(tnode1);
m1.appendChild(tnodebr);
var textnodex=document.createTextNode(t1.value);
tnode2=tnode1.appendChild(textnodex ); <---------我想應該是這裡要修改
我直接做,得到是斷行
}
function hidemenu(){
m1.style.visibility="hidden";
}
function showmenu(){
m1.style.visibility="visible";
event.cancelBubble=true;
}
</script>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.65.53
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):