Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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 如何将参数从一个html页面传递到另一个html页面_Javascript_Html - Fatal编程技术网

Javascript 如何将参数从一个html页面传递到另一个html页面

Javascript 如何将参数从一个html页面传递到另一个html页面,javascript,html,Javascript,Html,我有一个带有输入文本框的HTML页面。现在我需要将该值传递到另一个HTML页面并读取该值 我的第一个HTML页面代码: <!DOCTYPE html> <html> <head> <form target="_blank" action="indextable.html" method="GET"> <input type="managerid" class="form-control" id="ManagerId" ty

我有一个带有输入文本框的HTML页面。现在我需要将该值传递到另一个HTML页面并读取该值

我的第一个HTML页面代码:

  <!DOCTYPE html>
  <html>
  <head>
 <form target="_blank" action="indextable.html" method="GET"> 

 <input type="managerid" class="form-control" id="ManagerId" type ="text" 
  autocomplete="off"  maxlength="8" onkeyup="alphanumOnly(this)" 
   placeholder="ManagerId"></input>

 <button id="submit" class="btn btn-primary" style="margin-top: 3px;"  
 this.disabled = true;  >Submit</button>

 <input type="reset" class="btn btn-primary" style="margin-top: 3px;" 
 value="Reset" onClick="window.location.reload()"></input>   
 </form>
     <!DOCTYPE html>
     <html>
     <head>
     <script src="index.js" type="text/javascript"></script>
     <body>
     <script type="text/javascript">
     getReporteeList();      //This is javascript function which is there 
                                    in the index.js file
     </script>
     </body>
     ...
请让我知道我哪里出错了。如果可能,请提供一些示例代码。提前感谢

我的index.js代码

        function alphanumOnly(input){
        var regex = /[^a-zA-Z0-9]/gi;
        input.value = input.value.replace(regex, "");
         }
        var name = document.getElementById('ManagerId').value;
        function getReporteeList() {
        var name = document.getElementById('ManagerId').value;
        console.log(name); 
        $.ajax({
      url:'http://localhost:8088/JirasTrackingApp/
      reporter/Reportees/ReporteeList/'+ $("#ManagerId").val(),
      type:'GET',
      "crossDomain": true,
      beforeSend: function(xhr){
     },

      dataType: 'json',
      success: function(result){   
         var end = new Date().getTime();
         var dur = end - start;
         console.log("millisecs passed",dur);   
           var  size = result.length;
           var content = '';
           var number = 1;
           if(size>0){
            document.getElementById('table').style.display="block";
           $.each(result,function(key,value){
               var num    = number++;
               content += '<tbody>';
               content += '<tr>';
               content += '<td>'+num+'</td>';
               content += '<td>'+value.Name+'</td>';
               content += '<td>'+value.UserId.toUpperCase()+'</td>';
               content += '<td>'+'<a href="#" onclick ="getJira(\'' + value.UserId + '\')">'+value.count+'</a>'+'</td>';
               content += '</tr>';
               content += '<tbody>';
           });

           $('#employee_table').append(content);

        }   
           else{
             alert("Please enter a Valid Associate Id");
         }
         },
        //error: function(result){
            error:function(jqXHR,exception){
               // alert("Invalid input");
               console.log(jqXHR);
               var msg='';
               if (jqXHR.status === "ERR_CONNECTION_REFUSED") {
                msg = 'Connection time out error.';
                alert(msg);
               }
               if (jqXHR.status == 500) {
                //msg = 'Please enter an valid input';
                alert("Please enter an valid input"+ "\n" + "The input must be started with 2 charactes"+
                "\n" + "Followed by 6 digits");
        }
    }

 });
函数字母(输入){
变量regex=/[^a-zA-Z0-9]/gi;
input.value=input.value.replace(regex,“”);
}
var name=document.getElementById('ManagerId').value;
函数getReporteeList(){
var name=document.getElementById('ManagerId').value;
console.log(名称);
$.ajax({
网址:'http://localhost:8088/JirasTrackingApp/
reporter/Reportees/ReporteeList/'+$(“#ManagerId”).val(),
类型:'GET',
“跨域”:正确,
发送前:函数(xhr){
},
数据类型:“json”,
成功:函数(结果){
var end=new Date().getTime();
var dur=结束-开始;
日志(“毫秒传递”,dur);
变量大小=result.length;
var内容=“”;
var数=1;
如果(大小>0){
document.getElementById('table').style.display=“block”;
$。每个(结果、函数(键、值){
var num=数字++;
内容+='';
内容+='';
内容+=''+num+'';
内容+=''+值。名称+'';
content+=''+value.UserId.toUpperCase()+'';
内容+=''+''+'';
内容+='';
内容+='';
});
$('#employee_table')。追加(内容);
}   
否则{
警报(“请输入有效的员工Id”);
}
},
//错误:函数(结果){
错误:函数(jqXHR,异常){
//警报(“无效输入”);
console.log(jqXHR);
var msg='';
if(jqXHR.status==“错误连接被拒绝”){
msg='连接超时错误';
警报(msg);
}
如果(jqXHR.status==500){
//msg='请输入有效的输入';
警报(“请输入有效输入”+“\n”+“输入必须以2个字符开头”+
“\n”+“后接6位”);
}
}
});

您的字段需要具有
name
属性才能传递值,因为
id
不会这样做


index.js中的javascript DOM元素选择器(
document.getElementById('ManagerId').value
等)正在查找第2页上看似不存在的元素。您需要做更多的工作,才能使用
window.location.search()从URL中实际提取参数
。请参阅:

可能重复的。你能从index.js提供你的代码吗?你确定我会分享javascript代码吗?我已经通过添加索引更新了代码。jsHey非常感谢我能够获取id。再次感谢
        function alphanumOnly(input){
        var regex = /[^a-zA-Z0-9]/gi;
        input.value = input.value.replace(regex, "");
         }
        var name = document.getElementById('ManagerId').value;
        function getReporteeList() {
        var name = document.getElementById('ManagerId').value;
        console.log(name); 
        $.ajax({
      url:'http://localhost:8088/JirasTrackingApp/
      reporter/Reportees/ReporteeList/'+ $("#ManagerId").val(),
      type:'GET',
      "crossDomain": true,
      beforeSend: function(xhr){
     },

      dataType: 'json',
      success: function(result){   
         var end = new Date().getTime();
         var dur = end - start;
         console.log("millisecs passed",dur);   
           var  size = result.length;
           var content = '';
           var number = 1;
           if(size>0){
            document.getElementById('table').style.display="block";
           $.each(result,function(key,value){
               var num    = number++;
               content += '<tbody>';
               content += '<tr>';
               content += '<td>'+num+'</td>';
               content += '<td>'+value.Name+'</td>';
               content += '<td>'+value.UserId.toUpperCase()+'</td>';
               content += '<td>'+'<a href="#" onclick ="getJira(\'' + value.UserId + '\')">'+value.count+'</a>'+'</td>';
               content += '</tr>';
               content += '<tbody>';
           });

           $('#employee_table').append(content);

        }   
           else{
             alert("Please enter a Valid Associate Id");
         }
         },
        //error: function(result){
            error:function(jqXHR,exception){
               // alert("Invalid input");
               console.log(jqXHR);
               var msg='';
               if (jqXHR.status === "ERR_CONNECTION_REFUSED") {
                msg = 'Connection time out error.';
                alert(msg);
               }
               if (jqXHR.status == 500) {
                //msg = 'Please enter an valid input';
                alert("Please enter an valid input"+ "\n" + "The input must be started with 2 charactes"+
                "\n" + "Followed by 6 digits");
        }
    }

 });