Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击获取2个getElementById元素_Javascript_Jquery - Fatal编程技术网

Javascript 单击获取2个getElementById元素

Javascript 单击获取2个getElementById元素,javascript,jquery,Javascript,Jquery,我必须修改以下代码以包含persDonateAllocat的值: <script type="text/javascript"> function doAddPersonalDonation(personaldonation, id){ if(isNaN(personaldonation)){ alert("Please enter only round numbers and no cents.");

我必须修改以下代码以包含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>

函数doAddPersonal捐款(Personal捐款,id){
if(isNaN(个人捐赠)){
警告(“请只输入整数,不输入美分”);
}否则{
window.location=“adopt.php?action=add&personaldivation=“+personaldivation+”&id=“+id+”&all=“+persDonateAllocat;
}
}
我尝试了下面的代码,但现在单击链接没有任何作用:

<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>

函数doAddPersonal捐款(Personal捐款,id){
var persDonateAllocat=document.getElementById('persDonateAllocat')。值;
if(isNaN(个人捐赠)){
警告(“请只输入整数,不输入美分”);
}否则{
window.location=“adoptions_2.php?action=add&personaldivation=“+personaldivation+”&id=“+id+”&all=“+persDonateAllocat;
}
}
这个怎么样

HTML:

<a id="myLink">Some link</a>
<input id="personaldonation" />
<input id="persDonateAllocat" />
$("#myLink").click(function() {
    var id = 123;
    var personaldonation = $("#personaldonation").val();
    var persDonateAllocat = $("#persDonateAllocat").val();
    window.location = "adopt.php?action=add&personaldonation=" + personaldonation + "&id=" + id + "&all=" + persDonateAllocat;
});

请详细说明,我不是Javascript fundi?我添加了一个示例回答我现在已经解决了这个问题,并编辑了我的问题以反映我使用的解决方案。有人发布了答案,但删除了它,即使它是正确的解决方案。谢谢你的帮助。好的,没问题。谢谢