javascript
  • arrays
  • struts
  • 2013-10-08 26 views 0 likes 
    0

    确定我有这样的一个jsp页面在struts添加到阵列中的JavaScript

    <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); 
    } 
    

    从而使新的对象与数组中的其他对象一起显示出来,所以当我提交这个页面时,它会被引用到带有数组中对象的窗体中。

    有没有简单的方法来做到这一点?

    回答

    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); 
    } 
    
    相关问题