Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery append Stripe pay按钮返回[object HTMLScriptElement]_Javascript_Php_Jquery - Fatal编程技术网

Javascript Jquery append Stripe pay按钮返回[object HTMLScriptElement]

Javascript Jquery append Stripe pay按钮返回[object HTMLScriptElement],javascript,php,jquery,Javascript,Php,Jquery,我正试图通过jquery附加“带卡支付”按钮。我之所以添加它,是因为我希望在用户满足某个特定需求后显示它,而且价格是可变的 到目前为止我有这个代码 var script=document.createElement('script'); script.src="https://checkout.stripe.com/checkout.js"; script.class="stripe-

我正试图通过jquery附加“带卡支付”按钮。我之所以添加它,是因为我希望在用户满足某个特定需求后显示它,而且价格是可变的

到目前为止我有这个代码

var script=document.createElement('script');
                            script.src="https://checkout.stripe.com/checkout.js";
                            script.class="stripe-button";
                            $(script).prop({"data-key" : "pk_test_gJIeYpuvZc56uI22j5yr7h3s", "data-amount" : '"' + amount_paid + '"', "data-name" : "website.com", "data-description" : '"' + purch_item + ' ($'+ final_value +')"', "data-image" : "image.png"});
$('.payment_stripe_span').append('<form action="make_payment.php" method="POST">' + script + '</form>');
var script=document.createElement('script');
script.src=”https://checkout.stripe.com/checkout.js";
script.class=“条带按钮”;
$(script).prop({“数据键”:“pk_test_gJIeYpuvZc56uI22j5yr7h3s”,“数据量”:“'+amount_paid+”,“数据名”:“website.com”,“数据描述”:“'+purch_item+”($'+final_value+)”,“数据图像”:“image.png”);
$('.payment\u stripe\u span')。追加(''+script+'');
但是,这会打印[object HtmlScript Element]


如何使按钮显示?

您正在使用对象作为字符串。这是你的解决方案

下面是修改后的代码。我使用了javascript的setAttribute方法

var script=document.createElement('script');
var amount_paid = 10;
var purch_item = 'Test';
var final_value = 15;

script.src="https://checkout.stripe.com/checkout.js";

script.setAttribute("class", "stripe-button");
script.setAttribute("data-key", "pk_test_gJIeYpuvZc56uI22j5yr7h3s");
script.setAttribute("data-amount", amount_paid);
script.setAttribute("data-name", "website.com");
script.setAttribute("data-description", '"' + purch_item + ' ($'+ final_value +')"');
script.setAttribute("data-image", "image.png");

$('.payment_stripe_span').append('<form action="make_payment.php" method="POST" id="my_frm">Form ( Inspect here to check if the DOM is added or not? )</form>');

$(script).appendTo("#my_frm");
var script=document.createElement('script');
已支付的风险值金额=10;
var purch_项目=‘测试’;
var最终值=15;
script.src=”https://checkout.stripe.com/checkout.js";
script.setAttribute(“类”、“条带按钮”);
script.setAttribute(“数据键”、“pk_测试_gJIeYpuvZc56uI22j5yr7h3s”);
script.setAttribute(“数据金额”,支付的金额);
script.setAttribute(“数据名”,“website.com”);
script.setAttribute(“数据描述”,“采购项目+”($”+最终值+)”);
setAttribute(“数据图像”,“image.png”);
$('.payment_stripe_span').append('表单(检查此处是否添加了DOM?);
$(脚本).appendTo(“#my_frm”);

链接到jsfiddle

脚本标记显示出来。但是,实际的按钮没有出现。使用更新的代码,您就有了解决方案。它在jsfiddle上运行良好