【问题标题】:How can I pass a date from my Jquery date picker to a parameter of a div element?如何将 Jquery 日期选择器中的日期传递给 div 元素的参数?
【发布时间】:2016-04-19 17:07:26
【问题描述】:

所以我正在尝试创建一个 Shopify 购买按钮,该按钮链接到特定日期的产品。我需要将选定的日期发送到产品句柄,然后让 shopify 按钮显示该产品,或者说该产品不存在。这是我所拥有的:

<html>
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">    <head>
    </head>
    <body>
    <div id="buttonId" data-embed_type="product" data-shop="maritix.myshopify.com" data-product_name="Ferry Riide" data-product_handle="ferry-riide" data-has_image="false" data-display_size="compact" data-redirect_to="cart" data-buy_button_text="Add to cart" data-buy_button_out_of_stock_text="Out of Stock" data-buy_button_product_unavailable_text="Unavailable" data-button_background_color="7fb466" data-button_text_color="ffffff" data-product_modal="false" data-product_title_color="000000" data-next_page_button_text="Next page">
    </div>



    <noscript><a href="https://maritix.myshopify.com/cart/17754591620:1" target="_blank">Buy Ferry Ride</a></noscript>
    <form>
        <p id="date"><input type="text" id="datepicker"></p>
    </form>
    </body>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <script type="text/javascript">

    document.getElementById('ShopifyEmbedScript') || document.write('<script type="text/javascript" src="https://widgets.shopifyapps.com/assets/widgets/embed/client.js" id="ShopifyEmbedScript"><\/script>');
  </script>
  <script>
      $(function() {
        $( "#datepicker" ).datepicker();
        var date = $("#date").text;
        $("#buttonId").data-product_handle = date;
        $("#buttonId").data-product_name = date;
      });
  </script>

</html>

对不起,如果这是一团糟,我在 javascript/html 中非常生疏。

【问题讨论】:

    标签: jquery html datepicker shopify


    【解决方案1】:

    你差一点就吃完了

     $("#buttonId").data-product_handle = date;
     $("#buttonId").data-product_name = date;
    

    应该是

     $("#buttonId").data('product_handle', date);
     $("#buttonId").data('product_name' , date);
    

     $("#buttonId").attr('data-product_handle', date);
     $("#buttonId").attr('data-product_name' , date);
    

    希望有帮助

    【讨论】:

    • 这很有帮助。 I am now trying something a little different, so when a date is selected it adds the buy button into a div element.但是,当我这样做时,页面只是不断尝试从 widgets.shopifyapps.com document.write('');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多