gpt4 book ai didi

jquery - PayPal:在多个选项框之间切换?

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:34 26 4
gpt4 key购买 nike

我一直在阅读有关如何使用 PayPal 表单的资料。我创建了一个使用选项的表单,但我希望能够根据他们选择选项 A 还是选项 B 在两个下拉框之间切换...

(我发现的唯一一个非常接近的问题是 -- Creating Multiple Select Option Box in Paypal Shopping Cart -- 我不明白。)

下面是一些示例代码:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" data-abide>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="matt.roberts.33@gmail.com">
<input type="hidden" name="bn" value="MRobertsDesign_BuyNow_WPS_CA">
<input type='hidden' name='lc' value='CA'>
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="return" value="http://mrobertsdesign.ca/design/payments/completed/">
<input type="hidden" name="cancel_return" value="http://mrobertsdesign.ca/design/payments/cancelled/">
<input type="hidden" name="item_number" value="service-plan">

<input type="text" placeholder="What is your name?" id="pack_name" name="os1" maxlength="100">

<select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>

<!-- Options A (Basic) -->
<select id="pack_time" name="os0">
<option value="">Choose your hours:</option>
<option value="2hrs">2 Hours - $90.00</option>
<option value="3hrs">3 Hours - $180.00</option>
<option value="4hrs">4 Hours - $228.00</option>
</select>
<input type="hidden" name="option_select0" value="2hrs">
<input type="hidden" name="option_amount0" value="90.00">
<input type="hidden" name="option_select1" value="3hrs">
<input type="hidden" name="option_amount1" value="180.00">
<input type="hidden" name="option_select2" value="4hrs">
<input type="hidden" name="option_amount2" value="228.00">

<!-- Options B (Advanced) -->
<select id="pack_time" name="os0">
<option value="">Choose your hours:</option>
<option value="2hrs">2 Hours - $190.00</option>
<option value="3hrs">3 Hours - $240.00</option>
<option value="4hrs">4 Hours - $328.00</option>
</select>
<input type="hidden" name="option_select0" value="2hrs">
<input type="hidden" name="option_amount0" value="190.00">
<input type="hidden" name="option_select1" value="3hrs">
<input type="hidden" name="option_amount1" value="240.00">
<input type="hidden" name="option_select2" value="4hrs">
<input type="hidden" name="option_amount2" value="328.00">

<input type="hidden" name="on1" value="Client">
<input type="hidden" name="on0" value="Hours">
<input type="submit" name="submit" class="button radius payments-buy" value="Buy Now">
</form>

这个想法是,当有人选择基本或高级时:

    <select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>

它将下拉选项分别更改为 A 或 B。

现在我不确定该怎么做,有人有什么想法吗?我不确定您是否理解我在做什么,但请问我是否需要更多说明,我不确定我还能说些什么。

我对 PHP 了解多一点,所以我明白了...当有人单击该下拉框并选择 Basic 或 Advance 时,它​​需要触发一个 jQuery 脚本,该脚本将首先检查以查看单击的内容遍历数组中的值并填充表单。我只是不知道该怎么做,有人想试一试吗?


为了举例,我非常想获得这个伪 php 代码的 JS/jQuery 版本:

<select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>

<?php
// I know this doesn't work but for the sake of example
if (select.pack_type option.basic.selected) {
var $pack_type = 'basic';
} elseif (select.pack_type option.advanced.selected) {
var $pack_type = 'advanced';
} else {
var $pack_type = NULL;
}

// Basic
$plan['basic'][] = array(
'hours' => '2 Hours',
'price' => '90.00',
);
$plan['basic'][] = array(
'hours' => '3 Hours',
'price' => '120.00',
);
$plan['basic'][] = array(
'hours' => '4 Hours',
'price' => '250.00',
);

// Advanced
$plan['advanced'][] = array(
'hours' => '2 Hours',
'price' => '190.00',
);
$plan['advanced'][] = array(
'hours' => '3 Hours',
'price' => '220.00',
);
$plan['advanced'][] = array(
'hours' => '4 Hours',
'price' => '350.00',
);

// Other variables
$i = 0;

if ($pack_type == 'basic') {
// Echo basic
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option>';
foreach ($plan['basic'] as $prices) {
echo '<option value="' . $prices['hours'] . '">' . $prices['hours'] . ' - $' . $prices['price'] . '</option>';
}
echo '</select>';
foreach ($plan['basic'] as $prices) {
echo '<input type="hidden" name="option_select' . $i++ . '" value="' . $prices['hours'] . '"><input type="hidden" name="option_amount' . $i++ . '" value="' . $prices['price'] . '">';
}
} elseif ($pack_type == 'advanced') {
// Echo advanced
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option>';
foreach ($plan['advanced'] as $prices) {
echo '<option value="' . $prices['hours'] . '">' . $prices['hours'] . ' - $' . $prices['price'] . '</option>';
}
echo '</select>';
foreach ($plan['advanced'] as $prices) {
echo '<input type="hidden" name="option_select' . $i++ . '" value="' . $prices['hours'] . '"><input type="hidden" name="option_amount' . $i++ . '" value="' . $prices['price'] . '">';
}
} else {
// Echo nothing
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option></select>';
}
?>

最佳答案

Paypal 为您提供了选择不同价格的产品下拉菜单的选项。

  1. 登录 Paypal 。
  2. 转到配置文件选择“我的销售工具”
  3. 点击“管理我的付款按钮”旁边的更新
  4. 创建一个新按钮
  5. 勾选“添加带有价格/选项的下拉菜单”复选框
  6. 您将看到如下图所示的屏幕。

enter image description here

添加:这是一个 jsfiddle,它可能有助于您实现目标。下拉菜单,将在选择时显示和隐藏单独的按钮。

查询

    $('select.div-toggler').change(function(){
var target = $(this).data('target');
$(target).children().addClass('hide');
var show = $("option:selected", this).data('show');
$(show).removeClass('hide');
});

http://jsfiddle.net/TLBvx/61/

关于jquery - PayPal:在多个选项框之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30364026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com