当我更改下拉菜单值时,我需要一些javascript来帮助替换链接的某个部分。 我想通过javascript onchange of dropdown menue替换部分链接。因此,当我更改下拉菜单时,我想通过 var e 更改下面链接中的数字theTotal = 12 :
<a class="btn_full" href="/traveltour/index.php/paypal/buy?theTotal=12&description=Pinko+Pallino+&quantity=1&tour_id=6&tourextra_id=11&guide_id=35">Go to payment</a>
$(document).ready(function () {
$("#Toursextra_count").on("change", function () {
var a = 22;
var b = $(this).find("option:selected").attr("value") * a;
var c = $(this).find("option:selected").attr("value");
var d = (b*0.10).toFixed(2);
var e = parseFloat(d)+parseFloat(b);
$(".totalcash ").text(b);
$(".adults").text(c);
$(".comission").text(d);
$(".grantotal").text(e);
});
});
答案 0 :(得分:1)
您可以.replace()
使用regular expression
来操纵链接的href
属性,如下所示:
╔══════╦════════════╦════════════╗
║ Item ║ Weekend ║ Week_Total ║
╠══════╬════════════╬════════════╣
║ 1 ║ 2015-01-03 ║ 92 ║
║ 2 ║ 2015-01-03 ║ 95 ║
║ 1 ║ 2015-06-27 ║ 4 ║
║ 2 ║ 2015-06-27 ║ 66 ║
║ 1 ║ 2015-07-04 ║ 12 ║
║ 2 ║ 2015-07-04 ║ 12 ║
╚══════╩════════════╩════════════╝
&#13;
$(document).ready(function () {
$("#Toursextra_count").on("change", function () {
var a = 22;
var b = $(this).val() * a;
var c = $(this).val();
var d = (b*0.10).toFixed(2);
var e = parseFloat(d)+parseFloat(b);
$(".totalcash ").text(b);
$(".adults").text(c);
$(".comission").text(d);
$(".grantotal").text(e);
var url = $('#myBtn').attr('href');
var newSection = 'theTotal='+e+'&'
url = url.replace(/theTotal=[\d.]+&/,newSection)
$('#myBtn').attr('href',url);
});
});
&#13;