<head>
<script type="text/javascript">
$(document).ready(function(){
$('#pickhour').change(function(){
pickhour1 = $(this).val();
$("#link1").attr("href", "http://lezkrlzekrzlmrez/" + pickhour1 + "/rzerzetztzerze/");
});
});
</script>
</head>
<body>
<select id="pickhour" name="pickhour">
<option value="1">1H</option>
<option value="2" selected>2H</option>
<option value="3">3H</option>
<option value="4">4H</option>
</select>
<a href="" id="link1">That link</a>
</body>
&#13;
大家好,我今天的问题是.attr不适用于我的。我想要&#34; link1&#34;的href。通过更改&#34; pickhour&#34;中的选择选项动态更新。我尝试了很多东西,但我对JS并不是很聪明,我希望有人会理解什么是错的,它似乎很容易......但不是! &GT;&LT;
答案 0 :(得分:2)
添加到您的<HEAD>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
答案 1 :(得分:0)
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="buybtn">
<select id="pickhour" name="pickhour">
<option value="1">1H</option>
<option value="2" selected>2H</option>
<option value="3">3H</option>
<option value="4">4H</option>
</select>
</div>
<div id="buybtn2">
<a id="egglink" >Reserver un cours</a>
</div>
<script>
$(document).ready(function(){
$('#pickhour').change(function(){
pickhour1 = $(this).val();
$("#egglink").attr("href", "http://school.egg-one.com/private-lesson/program-choice/program_choice/" + pickhour1 + "/player_id/87946");
});
});
</script>
</body>