第二次点击提交按钮时出错 第一次没问题 求高手改下 谢谢 主要是addevent方法
当组件注册和方法注册都写正确后点提交 第一次显示事件没填(正确) 但什么都不做再提交一次就提交了 并且 compevents数组显示undefined 不知是哪里出错了啊 主要在addevents方法里吧?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
select{
width:154px;
text-align:center;
}
</style>
<script type="text/javascript">
var method=[];
var compevents=[];
function init(){
var a=navigator.appName;
if(a=="Netscape"){
document.getElementById("component1").style.top="-14px";
document.getElementById("component2").style.top="-14px";
document.getElementById("component3").style.top="-14px";
}else{
document.getElementById("component1").style.top="-8px";
document.getElementById("component2").style.top="-8px";
document.getElementById("component3").style.top="-14px";
}
var form=document.forms[0];
var length=form.length;
for(var i=0;i<length;i++){
form.elements[i].onblur=confirmContext;
}
}
function confirmContext(a){
var type=typeof(a);
if(type=="object"){
if(!this.value||this.value.length==0){
this.style.backgroundColor="#FF9933";
return false;
}else{
this.style.backgroundColor="#FFFFFF";
return true;
}
}else if(type=="string"){
a=document.getElementById(a);
if(!a.value||a.value.length==0){
a.style.backgroundColor="#FF9933";
return false;
}else{
a.style.backgroundColor="#FFFFFF";
return true;
}
}
}
function addmethod(){
if(!confirmContext("methodName")||!confirmContext("methodDesc")||!confirmContext("returnType")||!confirmContext("methodType")){
return;
}
method[method.length]="方法名称:"+document.getElementById("methodName").value+"\t"+"方法描述:"+document.getElementById("methodDesc").value+"\t"+"返回值类型:"+
document.getElementById("returnType").value+"\t方法类型:"+document.getElementById("methodType").value;
document.getElementById("methodcontext").innerHTML="";
for(var i=0;i<method.length;i++){
document.getElementById("methodcontext").innerHTML+=method[i]+"<br>";
}
document.getElementById("methodName").value="";
document.getElementById("methodDesc").value="";
document.getElementById("returnType").value="";
document.getElementById("methodType").value="";
var methodlength=document.getElementById("changemethod").length;
for(var i=0;i<methodlength;i++){
document.getElementById("changemethod").remove(0);
}
for(var i=0;i<method.length;i++){
document.getElementById("changemethod")[i]=new Option((i+1)+"",i+"");
}
}
function savemethod(){
if(!confirmContext("methodName")||!confirmContext("methodDesc")||!confirmContext("returnType")||!confirmContext("methodType")){
return;
}
addmethod();
document.getElementById("methodtable").style.display="none";
}
function addevent(){
if(!confirmContext("eventName")||!confirmContext("eventDesc")||!confirmContext("eventType")){
return;
}
compevents[compevents.length]="事件名称:"+document.getElementById("eventName").value+"\t"+"事件描述:"+document.getElementById("eventDesc").value+"\t"+"事件类型:"+
document.getElementById("eventType").value;
document.getElementById("eventcontext").innerHTML="";
for(var i=0;i<compevents.length;i++){
document.getElementById("eventcontext").innerHTML+=compevents[i]+"<br>";
}
document.getElementById("eventName").value="";
document.getElementById("eventDesc").value="";
document.getElementById("eventType").value="";
var eventlength=document.getElementById("changeevent").length;
for(var i=0;i<eventlength;i++){
document.getElementById("changeevent").remove(0);
}
for(var i=0;i<compevents.length;i++){
document.getElementById("changeevent")[i]=new Option((i+1)+"",i+"");
}
}
function saveevent(){
if(!confirmContext("eventName")||!confirmContext("eventDesc")||!confirmContext("eventType")){
return;
}
addevent();
document.getElementById("eventtable").style.display="none";
}
function deleteevent(){
var selected=document.getElementById("changeevent").selectedIndex;
compevents.splice(selected,1);
document.getElementById("eventcontext").innerHTML="";
for(var i=0;i<compevents.length;i++){
document.getElementById("eventcontext").innerHTML+=compevents[i]+"<br>";
}
var eventlength=document.getElementById("changeevent").length;
for(var i=0;i<eventlength;i++){
document.getElementById("changeevent").remove(0);
}
for(var i=0;i<compevents.length;i++){
document.getElementById("changeevent")[i]=new Option((i+1)+"",i+"");
}
}
function deletemethod(){
var selected=document.getElementById("changemethod").selectedIndex;
method.splice(selected,1);
document.getElementById("methodcontext").innerHTML="";
for(var i=0;i<method.length;i++){
document.getElementById("methodcontext").innerHTML+=method[i]+"<br>";
}
var methodlength=document.getElementById("changemethod").length;
for(var i=0;i<methodlength;i++){
document.getElementById("changemethod").remove(0);
}
for(var i=0;i<method.length;i++){
document.getElementById("changemethod")[i]=new Option((i+1)+"",i+"");
}
}
function comfirmsubmit(){
for(var i=0;i<10;i++){
if(!confirmContext(document.forms[0].elements[i].id)){
return false;
}
}
if(method==""||method.length==0){
alert("组件方法不能为空");
return false;
}
if(compevents=""||compevents.length==0){
alert("组件事件不能为空");
return false;
}
return true;
}
</script>
</head>
<body onload="init()">
<center>
<div style="width:75%; height:auto; border-color:#FFCC00; border-style:solid; border-width:2px; padding:40px;">
<form action="" method="post">
<div style="text-align:left;width:100%;height:43px;background-color:#FFECFF;border-top-color:#FF44FF;border-style:solid;border-width:1px;border-spacing:1px;border-bottom:none;border-left:none; border-right:none; overflow:hidden;">
<h2 id="component1" style="position:relative;top:5px;">组件注册</h2>
</div>
<table style="padding:40px;">
<tr>
<td>组件类型</td>
<td>
<select id="componentTypeId">
<option selected="selected" value="">----请选择----</option>
<option value="test">test</option>
</select>
</td>
<td>组件名称</td>
<td><input id="componentName" type="text"></td>
</tr>
<tr>
<td>组件描述</td>
<td><input id="componentDesc"type="text"></td>
<td>运行环境</td>
<td><input id="environment" type="text"></td>
</tr>
<tr>
<td>开发语言</td>
<td><input id="developLanguage" type="text"></td>
<td>组件版本</td>
<td><input id="version" type="text"></td>
</tr>
<tr>
<td>组件类别</td>
<td>
<select id="componentCategory">
<option selected="selected" value="">----请选择----</option>
<option value="0">客户端组件</option>
<option value="1">平台组件</option>
</select>
</td>
<td>开发者</td>
<td><input id="developer" type="text"></td>
</tr>
<tr>
<td>组件类名</td>
<td><input id="className" type="text"></td>
<td>组件地址</td>
<td><input id="componentURL" type="text"></td>
</tr>
</table>
<div style="text-align:left;width:100%;height:43px;background-color:#FFECFF;border-top-color:#FF44FF;border-style:solid;border-width:1px;border-spacing:1px;border-bottom:none;border-left:none; border-right:none; overflow:hidden;">
<h2 id="component2" style="position:relative;top:5px;">组件方法注册</h2>
</div>
<div align="right">
<select id="changemethod" style="width:50px">
<option value="0">0</option>
</select>
<input type="button" value="删除" onclick="deletemethod()">
</div>
<div id="methodcontext" align="left"></div>
<table id="methodtable" style="padding:40px;">
<tr>
<td>方法名称</td>
<td><input type="text" id="methodName"></td>
<td>方法描述</td>
<td><input type="text" id="methodDesc"></td>
</tr>
<tr>
<td>返回值类型</td>
<td><input type="text" id="returnType"></td>
<td>方法类型</td>
<td>
<select id="methodType">
<option value="" selected="selected">----请选择----</option>
<option value="0">构造方法</option>
<option value="1">初始化</option>
<option value="2">销毁</option>
<option value="3">显示方法</option>
<option value="4">业务逻辑方法</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="保存并继续新增" onclick="addmethod()"></td>
<td colspan="2" align="center"><input type="button" value="保存并不再增加" onclick="savemethod()"></td>
</tr>
</table>
<div style="text-align:left;width:100%;height:43px;background-color:#FFECFF;border-top-color:#FF44FF;border-style:solid;border-width:1px;border-spacing:1px;border-bottom:none;border-left:none; border-right:none; overflow:hidden;">
<h2 id="component3" style="position:relative;top:5px;">组件事件注册</h2>
</div>
<div align="right">
<select id="changeevent" style="width:50px">
<option value="0">0</option>
</select>
<input type="button" value="删除" onclick="deleteevent()">
</div>
<div id="eventcontext" align="left"></div>
<table id="eventtable" style="padding:40px;">
<tr>
<td>事件名称</td>
<td><input type="text" id="eventName"></td>
<td>事件描述</td>
<td><input type="text" id="eventDesc"></td>
</tr>
<tr>
<td>事件类型</td>
<td>
<select id="eventType">
<option value="" selected="selected">----请选择----</option>
<option value="0">一般事件</option>
<option value="1">获取用户数据</option>
<option value="2">获取模型数据</option>
<option value="3">获取选择器数据</option>
<option value="4">打开框架</option>
<option value="5">消息中心消息</option>
<option value="6">打开指定URL</option>
<option value="7">调用资源</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="保存并继续新增" onclick="addevent()"></td>
<td colspan="2" align="center"><input type="button" value="保存并不再增加" onclick="saveevent()"></td>
</tr>
</table>
<input type="submit" value="确认提交" onclick="return comfirmsubmit()">
</form>
</div>
</center>
</body>
</html>