西西木科技丨Shopify开发机构 2022-05-14 01:58 采纳率: 96.4%
浏览 10
已结题

实现了value和gpo-data-variant-id的转换,现在我想用同样的方法写第二个select,但是发现无效了,请问应该怎么改?

用以下的代码成功实现的value和gpo-data-variant-id的转换



   <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>       
 
    <div class="gpo-element gpo-form__group gpo-col-12 show-addon-for-input" data-element-id="select-2">
      <div class="gpo-hidden-data">
         <input type="hidden" data-field-name="select-2" value="snc" id="inputselect-2" name="properties[select-2]" gpo-data-variant-id="snc" gpo-data-product-handle="price" >
      </div>
      <label for="select-2" class="gpo-label ">
        <span class="label-content">install</span>
      </label>
      <div class="gpo-select">
        <select data-type="select" id="select-2" class="gpo-select" name="select-2" data-name="properties[select-2]" data-field-name="select-2" is="ms-dropdown" onchange="detail(this)">
          <option selected="" disabled="disabled" value="">Please Select</option>
            <option value="embedded" gpo-data-product-handle="price" gpo-data-variant-id="40268730171531" data-image="//cdn.shopify.com/s/files/1/0382/7263/0923/products/DM_20220507204825_001_medium.jpg?v=1651927745">embedded</option>
            <option value="plug-in" gpo-data-product-handle="price" gpo-data-variant-id="40268730204299" data-image="//cdn.shopify.com/s/files/1/0382/7263/0923/products/DM_20220507204825_001_medium.jpg?v=1651927745">plug-in</option>
        </select>
      </div>
    </div> 
                
         
<script>          
          
 function detail(xmmy)
    
    {
 var inputselect = document.getElementById("inputselect-2");inputselect.setAttribute("gpo-data-variant-id", $(xmmy).find('option:checked').attr("gpo-data-variant-id"));
 var inputselect = document.getElementById("inputselect-2");inputselect.setAttribute("value", $(xmmy).find('option:checked').attr("value"));
 
}
</script>

现在想接着写第二个select,但是有冲突,请问应该怎么改


<div class="gpo-element gpo-form__group gpo-col-12 show-addon-for-input" data-element-id="select-3">
      <div class="gpo-hidden-data">
         <input type="hidden" data-field-name="select-3" value="snc3" id="inputselect-3" name="properties[select-3]" gpo-data-variant-id="snc3" gpo-data-product-handle="price" >
      </div>
      <label for="select-3" class="gpo-label ">
        <span class="label-content">install3</span>
      </label>
      <div class="gpo-select">
        <select data-type="select" id="select-3" class="gpo-select" name="select-3" data-name="properties[select-3]" data-field-name="select-3" is="ms-dropdown" onchange="detail(this)">
          <option selected="" disabled="disabled" value="">Please Select</option>
            <option value="embedded3" gpo-data-product-handle="price" gpo-data-variant-id="40268730105995" data-image="//cdn.shopify.com/s/files/1/0382/7263/0923/products/DM_20220507204825_001_medium.jpg?v=1651927745">embedded3</option>
            <option value="plug-in3" gpo-data-product-handle="price" gpo-data-variant-id="40268730138763" data-image="//cdn.shopify.com/s/files/1/0382/7263/0923/products/DM_20220507204825_001_medium.jpg?v=1651927745">plug-in3</option>
        </select>
      </div>
    </div> 
                
         
<script>          
          
 function detail(xmmy3)
    
    {
 var inputselect = document.getElementById("inputselect-3");inputselect.setAttribute("gpo-data-variant-id", $(xmmy3).find('option:checked').attr("gpo-data-variant-id"));
 var inputselect = document.getElementById("inputselect-3");inputselect.setAttribute("value", $(xmmy3).find('option:checked').attr("value"));
 
}
</script>

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月22日
    • 创建了问题 5月14日

    悬赏问题

    • ¥15 孟德尔随机化怎样画共定位分析图
    • ¥18 模拟电路问题解答有偿速度
    • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
    • ¥15 误删注册表文件致win10无法开启
    • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
    • ¥60 ESP32怎么烧录自启动程序
    • ¥50 html2canvas超出滚动条不显示
    • ¥15 java业务性能问题求解(sql,业务设计相关)
    • ¥15 52810 尾椎c三个a 写蓝牙地址
    • ¥15 elmos524.33 eeprom的读写问题