单击

时间:2017-09-15 20:10:41

标签: javascript jquery html button

我有以下代码,并且我试图在新标签中打开按钮并生成链接,帮助?



$(document).ready(function() {
  $("#form").on('submit', function(e) {
    e.preventDefault();
    window.location.replace("https://www.payjunction.com/trinity/quickshop/add_to_cart_snap.action?store=paymentbutton&description=INVOICE NO. " + $("#invoice_number").val() + "&need_to_tax=no&need_to_ship=no&price=" + $("#payment_amount").val());
  });
});

<!DOCTYPE html>
<html dir="ltr">

<body> Enter your <b>Invoice Number</b> and <b>Payment Amount</b> below:
  <form id="form"> <input type="text" name="invoice_no" placeholder="Invoice Number" value="" id="invoice_number" required>
    <input type="text" name="payment_amount" placeholder="Payment Amount" value="" id="payment_amount" required>
    <button type="submit" id="button">Pay with Credit Card</button>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  </form>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

查看window.open()背后的文档。您可以将其绑定到按钮单击,将生成的URL传递给它,它将在新的选项卡/窗口中打开它。

即。在你的情况下,它可能看起来像这样:

$("#form").on('submit', function(e) {
    e.preventDefault();
    window.open("https://www.payjunction.com/trinity/quickshop/add_to_cart_snap.action?store=paymentbutton&description=INVOICE NO. " + $("#invoice_number").val() + "&need_to_tax=no&need_to_ship=no&price=" + $("#payment_amount").val());
});