0

我知道该函数需要使用 onclick 或任何事件来调用。但是是否有可能在没有用户处理的情况下获得隐藏值。

样品表格:

 $ID = 3;
 $Report1 = "Test1.docx";
 <form id = "Test" action="Nextpage.php">
 //Not sure how to call out my function over here...
 <input type="hidden" id="ID" name="ID" value="<?php echo $ID ?>"/> 
 <input type="hidden" id="ReportPath" name="ReportPath" value="<?php echo $ReportPath ?>"/> 
 //Once user click, function of RemoveDoc() will handle it.
 <input type="submit" id="Remove" name="<?php echo $Report1?>" value="Remove" title="Remove report1" onclick="return RemoveDoc(this.name, this.getAttribute('Report1'));" />

我的功能:

 function Remove(ID, ReportPath, Report1)
 {
xmlhttp1=new XMLHttpRequest();

xmlhttp1.open("GET","functions/call.php?ID="+ID+"&ReportPath="+ReportPath+"&Report1="+Report1,true);
xmlhttp1.onreadystatechange=function()
 {
    if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
     {
    document.getElementById("msg").innerHTML=           xmlhttp1.responseText;
     }
 }
xmlhttp1.send();
    return false;
 }

那么如何将输入的隐藏值传递到我的函数 Remove(ID,ReportPath...) 中,因为它现在已隐藏并且未采取任何操作。好心提醒。

4

1 回答 1

2

你可以得到

var id = document.getElementById('ID').value;
var reportpath  = document.getElementById('ReportPath').value;
var report1  = document.getElementById('Report1').value;

调用函数:

Remove(id, reportpath, report1);

为了让您更轻松。你可以使用jquery。只需将其包含在您的页面中:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<form id="Test" action="Nextpage.php">
 <input type="hidden" id="ID" name="ID" value="<?php echo $ID ?>"/> 
 <input type="hidden" id="ReportPath" name="ReportPath" value="<?php echo $ReportPath ?>"/> 

 <input type="submit" id="remove" name="<?php echo $Report1?>" value="Remove"/>
</form>

<script>
$('#remove').click(function(){
    var id = $('#ID').val();
    var reportpath  = $('#ReportPath').val();
    var report1  = $('#Report1').val(); //check this as I dont see it in your form

    //call your function from here
    Remove(id, reportpath, report1);
});

//function definition here
function Remove(id, reportpath, report1)...
</script>
于 2012-07-13T00:37:37.050 回答