[英]How do I use prop. to only be applied to the element clicked?
I am creating a payment form, part of which the user can select credit card or paypal. 我正在创建付款表格,用户可以选择其中的一部分,以选择信用卡或贝宝。 I am having issues with the display function.
我的显示功能有问题。 Should I be creating a new function for each element?
我应该为每个元素创建一个新功能吗? This is what I have:
这就是我所拥有的:
<p>Billing Infomation</p>
First Name: <input name="Billing_F_name" type="text" size="15"
value="Enter First Name"/> Last Name: <input name="Billing_L_name"
type="text" size="20" value="Enter Last Name"/><br />
Method of Payment:<br />
Credit Card <input name="payment" id="p1" type="radio" onclick="javascript:
payment()"/><br />
Paypal <input name="payment" id="p4" type="radio"
onclick="javascript:payment()"/><br />
<script language="javascript" >
function payment(click)
{
if(document.getElementById("p1"){
$('input:radio[name="payment1"][value="P_1"]').prop('checked=checked', true);
document.write('<? $P_Method = 'P_1'; ?>');
}
else if(document.getElementsById("p4")){
$('input:radio[name="payment4"][value="P_4"]').prop('checked=checked', true);}
document.write('<? $P_Method = 'P_4'; ?>');
}
</script>
BTW, just for your reference. 顺便说一句,仅供参考。 The PHP set variables that are being set go to a php switch method, displaying their respective elements, which functions properly at the moment.
正在设置的PHP设置变量转到php切换方法,显示它们各自的元素,此元素目前可以正常运行。
Pass the clicked element to the handler and use it. 将clicked元素传递给处理程序并使用它。
javascript:payment(this)
.. ..
function payment(el) {
$(el).doSomething()
}
for execute in php you need use AJAX 在PHP中执行,您需要使用AJAX
<script language="javascript">
function payment(dd)
{
if(dd.id=="p1")
document.write("<? $P_Method = 'P_1'; ?>");
else if(dd.id=="p4")
document.write("<? $P_Method = 'P_4'; ?>");
}
</script>
<p>Billing Infomation</p>
First Name: <input name="Billing_F_name" size="15" value="Enter First Name" type="text">
Last Name:
<input name="Billing_L_name" size="20" value="Enter Last Name" type="text"><br>
Method of Payment:<br>
Credit Card <input name="payment" id="p1" onclick="payment(this)" type="radio"><br>
Paypal <input name="payment" id="p4" onclick="payment(this)" type="radio"><br>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.