我知道getElementsByTagName并且getElementsByClassName需要一个索引标识符,以便将对象绑定到事件侦听器.
所以问题是,如何将事件监听器添加到使用 getElementsByTagName 或 找到的HTML元素集合中getElementsByClassName?
<input class="inputs" type="submit" value="Hello" />
<input class="inputs" type="submit" value="World" />
var inputElem = document.getElementsByTagName('input');
inputElem.addEventListener('click', function(){
alert(this.value);
}, false);
Run Code Online (Sandbox Code Playgroud)
我知道如何在jQuery中执行此操作,但我想知道如何使用纯JS执行此操作.
我试图让Stripe的Checkout自定义按钮为信用卡收费,但在输入信用卡详细信息后,它所做的就是最小化.我正在使用文档中的代码但我无法使其工作.简单的按钮很容易使用,我认为它只是简单地定制那个,但它是非常不同的.
这是代码:
付款页面
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="submit" value="Pay with card" id="customButton"/>
<?php require_once('./config.php'); ?>
<script>
var handler = StripeCheckout.configure({
key: '<?php echo $stripe['publishable_key']; ?>',
image: 'favicon.png',
token: function(token, args) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Imprintnation',
description: 'Decals',
amount: <?php echo $stripeTotal; ?>
});
e.preventDefault();
});
</script>
</form> …Run Code Online (Sandbox Code Playgroud) 我正在使用Stripe的自定义结帐按钮,我可以成功创建费用.我现在要做的是传递表单上的电子邮件地址并创建一个新客户.但是,电子邮件地址不会传递到我的服务器,而是直接转到Stripe.
我希望我能做到这样的事情:
//pass value from input field on previous page
$email = $_POST['email'];
// Create a Customer
$customer = Stripe_Customer::create(array(
"card" => $token,
"description" => "$email")
);
Run Code Online (Sandbox Code Playgroud)
但我不想两次询问用户他的电子邮件地址,因为Stripe的表格已经要求了.
如何捕获电子邮件地址以创建新客户?
我在Stripe的电子邮件收据中显示换行符时遇到问题.通过PHP中生成的电子邮件和说明<br>,\r\n逐字显示.
我也试过,nl2br但是因为那显示<br>我肯定它不会起作用.
PHP
$detail = "$name\r\n";
$detail .= "Length: $length,";
$detail .= " Width: $width,";
$detail .= "Color: $color,";
$detail .= "Qty: $qty\r\n";
$detail .= "Price: $price\r\n";
echo nl2br($detail);
Run Code Online (Sandbox Code Playgroud)
如何使用PHP在Stripe电子邮件收据上显示换行符?
我$_SESSION用来为我的网上商店动态创建表单.这些表单包含客户想要的产品的自定义信息.这是布局:
第1页
客户填写看起来像这样的表单:
<form action="page2" method="post">
<input type="text" name="size">
<input type="text" name="color">
<input type="submit" name="submit" value="Review Order">
</form>
Run Code Online (Sandbox Code Playgroud)
第2页
客户查看订单详情,并可选择添加更多产品.客户返回第1页订购另一个.所有客户的订单将以第2页的形式显示.
看起来像这样:
Size: 1
Color: blue
Click Here To Checkout
Size: 2
Color:green
Click Here To Checkout
Size:3
color:red
Click Here To Checkout
Run Code Online (Sandbox Code Playgroud)
我想要的是一个将所有订单添加到PayPal购物车的按钮.当然,他们可以通过点击单独添加每个订单Click Here To Checkout,但是他们将不得不经历一个大循环来添加多个产品.
我希望客户能够添加尽可能多的产品,然后单击一个按钮将所有订单添加到购物车.
这是我尝试的但显然不起作用:
<script>
$(document).ready(function(){
$('#clickAll').on('click', function() {
$('input[type="submit"]').trigger('click');
});
});
</script>
<form action="" method="post">
<input type="text" name="name">
<input type="submit" name="submit" value="submit">
</form>
<form action="" method="post">
<input type="text" name="name">
<input …Run Code Online (Sandbox Code Playgroud) 我想基于它从下面的API接收的有效负载来渲染组件
<Route path="/foo/bar" render={() => {
return (get('/some/api').then((res) => {
return <Baz data={res.data} />
}).catch((err) => console.log))
}} />
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误:
Objects are not valid as a React child (found: [object Promise]). If you
meant to render a collection of children, use an array instead.
Run Code Online (Sandbox Code Playgroud)
甚至当我做包裹Baz在[]
javascript asynchronous reactjs react-router react-router-v4
我有一个简短的脚本,通过乘以input值来计算数字.该脚本工作正常但现在我想添加if语句.例如:
HTML:
<label>Width</label><input type="text" id="width" />
<br>
<label>Length</label><input type="text" id="length" />
<br>
<label>Total</label><input type="text" id="total"/>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var w = $('#width').val();
var l = $('#length').val();
var total1 = 2;
var total2 = 3;
if((w * l) > 5){
total = total1 * (w + l);
parseInt($('#total').val('total'));
}
if((w * l) < 5){
totalnew = total2 * (w + l);
parseInt($('#total').val(totalnew));
}
Run Code Online (Sandbox Code Playgroud)
因此,如果(#width x #length) > 5,值(#width x #length)将乘以某个数字,在这种情况下为"2".
这是没有if语句的代码:http://jsfiddle.net/e45SJ/
如何使用我已经拥有的代码的if语句实现我想要实现的目标? …
javascript ×4
php ×4
jquery ×2
asynchronous ×1
checkout ×1
email ×1
forms ×1
html ×1
input ×1
paypal ×1
react-router ×1
reactjs ×1
session ×1