-1

我在 oscommerce 中有一些代码,使客户能够通过单击文本链接查看包含增值税或不含增值税的价格。我想将文本链接更改为如下所示:

“显示价格 [ X ] 含增值税 [ ] 不含增值税”(其中 [ ] 是单选按钮)

我尝试了一些我在网上找到的不同解决方案,但我不够熟练。我希望有人可以快速查看并给我一个提示?=)

<?php echo
'  <div>' .
'    ' . ((DISPLAY_PRICE_WITH_TAX == 'true') ? '<strong>' . TEXT_DISPLAYING_PRICES_WITH_TAX . '</strong>' : '<a href="' . tep_href_link(FILENAME_DEFAULT, 'action=toggle_tax&display_tax=true&uri='. urlencode($_SERVER['REQUEST_URI'])) . '">' . TEXT_DISPLAY_PRICES_WITH_TAX . '</a>') . '' .
'    ' . ((DISPLAY_PRICE_WITH_TAX == 'false') ? '<strong>' . TEXT_DISPLAYING_PRICES_WITHOUT_TAX . '</strong>' : '<a href="' . tep_href_link(FILENAME_DEFAULT, 'action=toggle_tax&display_tax=false&uri='. urlencode($_SERVER['REQUEST_URI'])) . '">' . TEXT_DISPLAY_PRICES_WITHOUT_TAX . '</a>') . 
'  </div>'?>
4

1 回答 1

0

如果您正在尝试做我认为您正在尝试做的事情,那么您希望允许用户显示含税/不含税的价格。

一种可能性是使用jQuery,一个 JavaScript 库。

如果您决定走这条路,您可以将每个价格打印到页面上,但隐藏用户不想看到的价格。

<html>
<head>

<!-- Include the jQuery Library via CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

</head>
<body>

<!-- Display Prices, hide one -->
<div class="with_vat">$xxx</div>
<div class="without_vat" style="display:none">$yyy</div>

<!-- Options -->
<input type="radio" name="vat_choice" value="1" checked />  Show Vat
<input type="radio" name="vat_choice" value="0" />  Exclude Vat

<!-- jQuery to Hide/Show the divs when radio is changed -->
<script>
$("input[name='vat_choice']").change(function(){

  // Get Value
  var vatChoice = $(this).val();

  if(vatChoice == 1){

    $('.with_vat').show();
    $('.without_vat').hide();

  }
  else{

    $('.with_vat').hide();
    $('.without_vat').show();

  }

});
</script>


</body>
</html>

您可以在此处查看实际代码:http: //jsfiddle.net/PKh3y/

您还可以通过单击单选按钮时重定向来实现所需的结果。下面的解决方案确实使用了(一点点)PHP。

<html>
<head>

<!-- Include the jQuery Library via CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

</head>
<body>

<!-- Display Prices depending on $_GET parameters -->
<?php if(!isset($_GET['without_vat'])): ?>
<div class="with_vat">$xxx</div>
<?php else: ?>
<div class="without_vat">$yyy</div>
<?php endif; ?>

<!-- Options -->
<input type="radio" name="vat_choice" value="1" checked />  Show Vat
<input type="radio" name="vat_choice" value="0" />  Exclude Vat

<!-- jQuery to redirect when radio is changed -->
<script>
$("input[name='vat_choice']").change(function(){

  // Get Value
  var vatChoice = $(this).val();

  if(vatChoice == 1){

     window.location = 'http://example.com/';

  }
  else{

    window.location = 'http://example.com/?without_vat=1';

  }

});
</script>


</body>
</html>

我希望能回答你的问题,祝你好运!

于 2013-01-24T16:18:33.587 回答