如果您正在尝试做我认为您正在尝试做的事情,那么您希望允许用户显示含税/不含税的价格。
一种可能性是使用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>
我希望能回答你的问题,祝你好运!