2×的getElementById元素我不得不修改下面的代碼,包括persDonateAllocat值:獲取有關點擊
<script type="text/javascript">
function doAddPersonalDonation(personaldonation, id){
if(isNaN(personaldonation)){
alert("Please enter only round numbers and no cents.");
}else{
window.location = "adopt.php?action=add&personaldonation=" + personaldonation + "&id=" + id + "&all=" + persDonateAllocat;
}
}
</script>
<a href=\"javascript:doAddPersonalDonation(
document.getElementById('personaldonation').value,$id
)\">Add To Cart</a>
我曾嘗試下面的代碼,但點擊該鏈接現在什麼都不做:
<a href=\"javascript:doAddPersonalDonation(personaldonation, persDonateAllocat){
document.getElementById('personaldonation').value,$id;
document.getElementById('persDonateAllocat').value;
} \">Add To Cart</a>
我加入這個,現在完美的作品:
<script type="text/javascript">
function doAddPersonalDonation(personaldonation, id){
var persDonateAllocat= document.getElementById('persDonateAllocat').value;
if(isNaN(personaldonation)){
alert("Please enter only round numbers and no cents.");
}else{
window.location = "adoptions_2.php?action=add&personaldonation=" + personaldonation + "&id=" + id + "&all=" + persDonateAllocat;
}
}
</script>
<a href=\"javascript:doAddPersonalDonation(
document.getElementById('personaldonation').value,$id
)
\">Add To Cart</a>
做這個 – martynas
你能否詳細說明請,我沒有使用Javascript眼底方法裏面? – Grant
我添加了一個示例答案 – martynas