0

我正在尝试使用 java 脚本创建一个表单,该表单已创建,但不会替换该表单的动态参数值。以下是我的表格......

var formVar='<form:form name="service_form" commandName="command1" action="/serviceProcess" method="post">';

formVar+='<label for="'+ paramsdata[2] + '">'+paramsdata[3]+'</label><br/>';
formVar+='<form:input type='+paramsdata[2]+' path="webParamMap['+paramsdata[2]+'].webValue"  value='+ paramsdata[5] +'  class="input"></form:input><br>' ;

 formVar+='<label for=" '+paramsdata[2]+' ">'+paramsdata[3]+'</label><br/>';
formVar+='<div id="select">';
formVar+='<form:select path="webParamMap[' +paramsdata[2] + '].webValue">';
formVar+='<form:option value='+paramdata[8]+'>'+paramdata[9]+'</form:option>';
 formVar+='</form:select></div>';
formVar+='</form:form>';

在上面的表单中,标签标签值(动态参数值)被更新,但表单:输入和选择标签值(动态参数值)在输出中没有更新。

请帮助我如何使用动态参数创建这些标签?

4

3 回答 3

0

通过以下脚本,每个元素都获得了正确的值。我想知道你为什么使用“

<script>
    var paramsdata = new Array();;
    paramsdata[2]='param2';
    paramsdata[3]='param3';
    paramsdata[5]='param5';
    paramsdata[8]='param8';
    paramsdata[9]='param9';

    var formVar='<form:form name="service_form" commandName="command1" action="/serviceProcess" method="post">';

    formVar+='<label for="'+ paramsdata[2] + '">'+paramsdata[3]+'</label><br/>';
    formVar+='<form:input type='+paramsdata[2]+' path="webParamMap['+paramsdata[2]+'].webValue"  value='+ paramsdata[5] +'  class="input"></form:input><br>' ;

    formVar+='<label for=" '+paramsdata[2]+' ">'+paramsdata[3]+'</label><br/>';
    formVar+='<div id="select">';
    formVar+='<form:select path="webParamMap[' +paramsdata[2] + '].webValue">';
    formVar+='<form:option value='+paramsdata[8]+'>'+paramsdata[9]+'</form:option>';
    formVar+='</form:select></div>';
    formVar+='</form:form>';
    document.body.innerHTML = formVar;
</script>
于 2012-11-19T11:50:31.033 回答
0

JAVA != JAVASCRIPT

注意:

<form:form>

这是服务器端 Java。

您的 Javascript 只是客户端。

于 2012-11-19T16:02:22.673 回答
0
<script>

//helper function to create the form
function getNewSubmitForm(){
 var submitForm = document.createElement("FORM");
 document.body.appendChild(submitForm);
 submitForm.method = "POST";
 return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
 var newElement = document.createElement("<input name='"+elementName+"' type='hidden'>");
 inputForm.appendChild(newElement);
 newElement.value = elementValue;
 return newElement;
}

//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(){
 var submitForm = getNewSubmitForm();
 createNewFormElement(submitForm, "field1", "somevalue");
 createNewFormElement(submitForm, "field2", "somevalue");
 submitForm.action= "someURL";
 submitForm.submit();
}
</script>

<input type="button" value="Click to create form and submit" onclick="createFormAndSubmit()">
于 2013-01-01T13:24:50.163 回答