0

OK私はこれをjspページに持っています

<div id="productList">  
  <logic:iterate id="product" indexId="aid" name="TeamMaintenanceForm" property="team.productList">                             
          <div id='<bean:write name="product" property="id" />' >
                <bean:write name="product" property="name" /> 
          </div>        
        </logic:iterate>                                
</div>  

今、私はオブジェクトをこの配列にJavaScriptのようなもので追加したいと思います

  function addProduct(){
       var object;
       object.name='newProduct';
       object.id=5;
       productList.add(newProduct);
}

新しいオブジェクトが配列内の他のオブジェクトと一緒に表示されるように、このページを送信すると、配列内のオブジェクトを含むフォームに送信されます。

これを行う簡単な方法はありますか?

4

1 に答える 1

0
  function addProduct(){
    var object;
    object.name='newProduct';
    object.id=5;

    // get the reference of div (productList)
    var productList = document.getElementById('productList')  ;

    // create the div structure of children
    var newProductDiv = "<div id='"+object.id +"' />'"+object.name + "</div>"; 

    // append the children to the productList div.
    productList.appendChild(newProductDiv);
 }

パラメータ化することができます

function addProduct(object){

    // get the reference of div (productList)
    var productList = document.getElementById('productList')  ;

    // create the div structure of children
    var newProductDiv = "<div id='"+object.id +"' />'"+object.name + "</div>"; 

    // append the children to the productList div.
    productList.appendChild(newProductDiv);
}
于 2013-10-08T13:28:43.380 に答える