日期:2014-05-16  浏览次数:20296 次

javascript 的一个问题
function   add(){
document.attackSolutionActionForm   =   new   Object();
document.attackSolutionActionForm.attack_event_code.value   = document.getElementsByName( "attack_event_codeC ")[0].value;
document.attackSolutionActionForm.attack_action.value   =
document.attack_meanC.innerText;
document.attackSolutionActionForm.attack_event_code.value   =
document.attack_actionC.innerText;

document.attackSolutionActionForm.action   =   "AddAttackSolutionAction.do ";
document.attackSolutionActionForm.submit();
}


其中,attackSolutionActionForm   不是实际存在的表单,因此   new   Object(),为什么在运行的时候提示   document.attackSolutionActionForm.attack_event_code   has   no   properties     ?


------解决方案--------------------
function add(){
var attackSolutionActionForm = document.createElement( "FORM ");
var attack_event_code = document.createElement( "INPUT ");
attack_event_code.value = document.getElementsByName( "attack_event_codeC ")[0].value;
var attack_action = document.createElement( "INPUT ");
attack_action.value = document.attack_meanC.innerText;
attackSolutionActionForm.method= "POST ";
attackSolutionActionForm.appendChild(attack_event_code);
attackSolutionActionForm.appendChild(attack_action);
attackSolutionActionForm.action = "AddAttackSolutionAction.do ";
attackSolutionActionForm.submit();
}
试试行不行~