2017-09-15 108 views
-3

我有下面的代碼,我試圖使按鈕打開一個新的選項卡與生成的鏈接,幫助?Javascript按鈕來打開新窗口點擊

$(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>

+0

你爲什麼不乾脆把'目標=「_空白」'的''

標籤? – Barmar

+0

問題是? – ochi

+0

@ochi:*«我試圖讓按鈕在新選項卡中打開»* –

回答

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()); 
});