【问题标题】:Using Javascript to redirect a page使用 Javascript 重定向页面
【发布时间】:2011-08-15 20:50:50
【问题描述】:

我有这段代码

<input type="image" src="/wp-content/themes/happy/images/add-to-cart.png" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" onclick="alert('Cart Updated');"/>

如何让该代码重定向到“example.com”而不是显示“警报”?

【问题讨论】:

    标签: javascript redirect


    【解决方案1】:
      window.location="http://www.example.com";
    

    【讨论】:

      【解决方案2】:
      <input type="image" src="/wp-content/themes/happy/images/add-to-cart.png" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" onclick="window.location='http://example.com';"/>
      

      注意 url 周围的单引号。

      【讨论】:

        【解决方案3】:
        document.location.href = 'http://www.example.com';
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-06-18
          • 1970-01-01
          • 2013-04-04
          • 1970-01-01
          • 2023-03-22
          • 1970-01-01
          • 1970-01-01
          • 2013-11-03
          相关资源
          最近更新 更多