2011-11-03 25 views
1

我有一个输入字段的形式,与JavaScript时,它会使第一个下面,当用户输入多于2个字符的同一输入字段。这个代码是:填写多于2个字符时添加第二个输入。 (javascript)(难一)

<h7> Optie 1: </h7><input type="text" name="input1" onkeyup="if (this.value.length > 1 && treated[this.name] != 1){ addOne(); treated[this.name] = '1'; }" id="productoptiesadd"> <h7>&euro;</h7> <input type="text" name="price1" id="productoptiesaddprice"> 

&

 <script> 
     treated = new Object(); 
     inputNumber = 1; 

     function addOne() { 

      //Create an input type dynamically. 
      var divElement = document.createElement("div"); 

      var element = document.createElement("input"); 
      inputNumber++; 
      element.setAttribute("name", "input" +inputNumber); 
      element.setAttribute("onkeyup", "if (this.value.length > 1 && treated[this.name] != 1){ addOne(); treated[this.name] = '1'; }"); 
      element.setAttribute("id", "productoptiesadd"); 

      var price = document.createElement("input"); 
      price.setAttribute("name", "price" +inputNumber); 
      price.setAttribute("id", "productoptiesaddprice"); 

      var foo = document.getElementById("japroductopties"); 

      var htag = document.createElement("h7"); 
      htag.innerHTML = "Optie " + inputNumber + ":"; 

      var htags = document.createElement("h7"); 
      htags.innerHTML = " € "; 

      divElement.appendChild(htag); 
      divElement.appendChild(element); 
      divElement.appendChild(htags); 
      divElement.appendChild(price); 
      foo.appendChild(divElement); 
      } 
    </script> 

这是工作正常,但现在我得到我的下一个挑战,因为第一个输入字段是增加一个产品选项,我得到了一个其他选项应该给予折扣。

这里是我的主要问题:“我如何获得尽可能多的折扣输入字段,因为有产品选项字段。”

为了让您在这里有更多信息的我是如何布局的头脑的截图:

Example layout

下面是部分的HTML代码,但最后输入字段应该是相同的金额因为有选项输入字段。

<div id="productoptiecheat"></div> 
          <div id="japroductopties"> 
           <h7> Optie 1: </h7><input type="text" name="input1" onkeyup="if (this.value.length > 1 && treated[this.name] != 1){ addOne(); treated[this.name] = '1'; }" id="productoptiesadd"> <h7>&euro;</h7> <input type="text" name="price1" id="productoptiesaddprice"> 
          </div><!-- Japroductopties --> 
          <div class="clear"></div> 
        <label>Product in aanbieding</label> 
         <select class="select" title="product in aanbieding" name="productinaanbieding" id="productaanbieding" onchange='SwitchHiddenDiv2();'> 
          <option value="jaaanbieding">Ja</option> 
          <option value="neeaanbieding">Nee</option> 
         </select> 
          <div id="productoptiecheat"></div> 
          <div id="jaaanbieding"> 
           <select class="select" title="plaats vd aanbieding" name="aanbiedingplaats" id="aanbiedingplaats"> 
            <option value="hompagerubriek">Aanbieding tonen op homepage & rubriek</option> 
            <option value="rubriek">Aanbieding tonen in rubriek</option> 
            <option value="homepage">Aanbieding tonen op de homepage</option> 
            <option value="niet">Aanbieding niet tonen</option> 
           </select><br /> 
           <h7>Optie 1: Normaal bedrag: <b>&euro;</b></h7><input type="text" id="productoptiesadd" /> <h7>Aanbieding:</h7> <input type="text" id="productoptiesaddprice" /><br /> 
           <h7>Optie 2: Normaal bedrag: <b>&euro;</b></h7><input type="text" id="productoptiesadd" /> <h7>Aanbieding:</h7> <input type="text" id="productoptiesaddprice" /><br /> 
           <h7>Optie 3: Normaal bedrag: <b>&euro;</b></h7><input type="text" id="productoptiesadd" /> <h7>Aanbieding:</h7> <input type="text" id="productoptiesaddprice" /><br /> 
           <h7>Optie 4: Normaal bedrag: <b>&euro;</b></h7><input type="text" id="productoptiesadd" /> <h7>Aanbieding:</h7> <input type="text" id="productoptiesaddprice" /><br /> 
          </div><!-- jaaanbieding --> 
          <div class="clear"></div> 

我希望some1能帮助我与此有关。

回答

0

纠正我,如果我错了,但它看起来像要添加这些行之一:

<h7>Optie 1: Normaal bedrag: <b>&euro;</b></h7><input type="text" id="productoptiesadd" /> <h7>Aanbieding:</h7> <input type="text" id="productoptiesaddprice" /><br /> 

...每一个以上的功能增加了一个产品/价格选项的时间。

我会说在名称=“aanbiedingplaats”SELECT标记下面的HTML中添加一个DIV。将其称为id =“折扣”并将此代码添加到您的功能中:

document.getElementById(“discounts”)。innerHTML + = yourOptionHTML;

我在这里使用了innerHTML,但可以随意将它扩展为类似于addOne()的函数。

相关问题