这是很久以前一个js巨强朋友(WM)做的,今天又找出来放在这以备不时之需!不做java的人就不用看了!
代码原创:WM
代码:
<html>
<body>
<select id="t1">
<option value="String">String</option>
<option value="int">int</option>
<option value="float">float</option>
<option value="long">long</option>
<option value="ArrayList">ArrayList</option>
</select>
<input type="text" id="t2">
<input type="button" value="add" onclick=addoption()>
<input type="button" value="del" onclick=deloption()>
<input type="button" value="get and set" onclick="formatCodes()">
<br>
<select size="5" id="t4" onclick="selectOption(this,t5)">
</select>
<select size="5" id="t5" onclick="selectOption(this,t4)">
</select>
<br>
<div id="t3"></div>
</body>
</html>
<script>
function selectOption(mid,oid)
{
var lin=mid.options.selectedIndex;
if(lin>=0)
{
oid.options[lin].selected=true
}
}
function addoption()
{
if(t2.value.length>0)
{
var op1=new Option(t1.value,t1.value);
t4.options.add(op1);
var op2=new Option(t2.value,t2.value);
t5.options.add(op2);
}
}
function deloption()
{
var lin=t4.options.selectedIndex;
if(lin>=0)
{
t4.remove(lin);
t5.remove(lin);
}
}
function formatCodes()
{
var str="";
for(var i=0;i<t4.length;i++)
{
str+=getCode(t4.options[i].value,t5.options[i].value);
}
for(var i=0;i<t4.length;i++)
{
str+=formatCode(t4.options[i].value,t5.options[i].value)+"\n";
}
t3.innerText=str;
}
function formatCode(temp1,temp2)
{
var str="public void set";
var lin=temp2;
var lin_1=lin.charAt(0)+"";
lin_1=lin_1.toUpperCase();
lin=lin_1+lin.substring(1,lin.length);
str+=lin+"("+temp1+" "+temp2+")\n";
str+="{\n\t this."+temp2+"="+temp2+";\n}";
str+=" \npublic "+temp1+" get"+lin;
str+="()\n{\n\t return "+temp2+";\n}";
return str;
}
function getCode(temp1,temp2)
{
var str="private "+temp1+" "+temp2+";\n";
return str;
}
</script>
posted on 2007-11-07 11:57
lk 阅读(222)
评论(1) 编辑 收藏 所属分类:
ajax&js