Javascript 单击add-on后使用jquery从输入中删除值

Javascript 单击add-on后使用jquery从输入中删除值,javascript,jquery,Javascript,Jquery,我想删除输入类型中onclcik之后存储的值。现在我想删除onclick的值。我使用复选框添加值,条件是如果复选框未选中,则添加值。现在我想删除选中条件下输入onclick中的匹配值,如果a HTML <ul class="Popular" id="Popular"> <li class="item odd" onclick="handleClick(334);" id=""> <span class="input-holder"><i

我想删除输入类型中onclcik之后存储的值。现在我想删除onclick的值。我使用复选框添加值,条件是如果复选框未选中,则添加值。现在我想删除选中条件下输入onclick中的匹配值,如果a

HTML

<ul class="Popular" id="Popular">
   <li class="item odd" onclick="handleClick(334);" id="">
      <span class="input-holder"><input type="checkbox" id="related-checkbox-334" class="checkbox related-checkbox" name="related_products[]" value="334">ADD</span>
      <div class="product" id="disbaledtoclick">
         <a disabled="" href="" title="" class="product-image"><img src="https://www.example.com/media/catalog/product/g/r/greeting.jpg" width="100px" height="100"></a>
         <div class="product-details">
            <p class="product-name"><a href="" disabled=""> 10 Handmade chocolates</a></p>
            <div class="price-box">
               <span class="regular-price" id="product-price-2-related">
               <span class="price" disabled="">249.0000</span></span>
            </div>
         </div>
      </div>
   </li>
   <li class="item odd" onclick="handleClick(338);" id="">
      <span class="input-holder"><input type="checkbox" id="related-checkbox-338" class="checkbox related-checkbox" name="related_products[]" value="338">ADD</span>
      <div class="product" id="disbaledtoclick">
         <a disabled="" href="" title="" class="product-image"><img src="https://www.example.com/media/catalog/product/w/h/white-teddy-6inch-addon.jpg" width="100px" height="100"></a>
         <div class="product-details">
            <p class="product-name"><a href="" disabled=""> Small Teddy Bear (6")</a></p>
            <div class="price-box">
               <span class="regular-price" id="product-price-2-related">
               <span class="price" disabled="">279.0000</span></span>
            </div>
         </div>
      </div>
   </li>
   <li class="item odd" onclick="handleClick(339);" id="">
      <span class="input-holder"><input type="checkbox" id="related-checkbox-339" class="checkbox related-checkbox" name="related_products[]" value="339">ADD</span>
      <div class="product" id="disbaledtoclick">
         <a disabled="" href="" title="" class="product-image"><img src="https://www.example.com/media/catalog/product/5/-/5-dairy-milk.jpg" width="100px" height="100"></a>
         <div class="product-details">
            <p class="product-name"><a href="" disabled=""> 5 Dairy milk 13 gms each</a></p>
            <div class="price-box">
               <span class="regular-price" id="product-price-2-related">
               <span class="price" disabled="">200.0000</span></span>
            </div>
         </div>
      </div>
   </li>
   <li class="item odd" onclick="handleClick(340);" id="">
      <span class="input-holder"><input type="checkbox" id="related-checkbox-340" class="checkbox related-checkbox" name="related_products[]" value="340">ADD</span>
      <div class="product" id="disbaledtoclick">
         <a disabled="" href="" title="" class="product-image"><img src="https://www.example.com/media/catalog/product/h/a/half-kg-kajukatli.jpg" width="100px" height="100"></a>
         <div class="product-details">
            <p class="product-name"><a href="" disabled=""> Half kg Kaju Katli</a></p>
            <div class="price-box">
               <span class="regular-price" id="product-price-2-related">
               <span class="price" disabled="">200.0000</span></span>
            </div>
         </div>
      </div>
   </li>
   <li class="item odd" onclick="handleClick(341);" id="">
      <span class="input-holder"><input type="checkbox" id="related-checkbox-341" class="checkbox related-checkbox" name="related_products[]" value="341">ADD</span>
      <div class="product" id="disbaledtoclick">
         <a disabled="" href="" title="" class="product-image"><img src="https://www.example.com/media/catalog/product/a/d/ad007_large_teddy_bear_gift_to_india.jpg" width="100px" height="100"></a>
         <div class="product-details">
            <p class="product-name"><a href="" disabled=""> Large Teddy Bear (12")</a></p>
            <div class="price-box">
               <span class="regular-price" id="product-price-2-related">
               <span class="price" disabled="">200.0000</span></span>
            </div>
         </div>
      </div>
   </li>
</ul>
点击输入保存值

 <input type="hidden" name="related_product" id="related-products-field" value="338,339,340">

如果(已检查){
var index=numArray.indexOf(cb);//在numArray中获取项目的索引
如果(索引>-1){
splice(索引,1);//从数组中删除项
}
document.getElementById('related-products-field')。value=numArray.join(“,”)
}

javascript有
splice()
函数从数组中删除项

JSFIDLE供参考:

 <input type="hidden" name="related_product" id="related-products-field" value="338,339,340">