如何在文本框中放置已发布的值

时间:2015-09-25 06:58:05

标签: javascript jquery html

在click.html中,onClick of clint_ip文本框正在重定向到index.html。我们将选择一些client_ip'在点击index.html中的提交按钮后,我能够检索click.html中的值。但是我无法将检索到的值保存到click.html的client_ip文本框中。我能够在" res"中获取值。变量

我的click.html

<html>
<head>
 <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<script type="text/javascript" src="http://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>

<script type="text/javascript" src="https://raw.githubusercontent.com/mpryvkin/Plugins/master/pagination/simple_numbers_no_ellipses.js"></script>

<link rel='stylesheet' href='style.css'>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
</head>
<body>
<div id="clicDiv">
Client IP :<input type="text" id="ipClick"  onclick="getValue();" name="Client IP" />
</div>
<script>


function getUSERIP(){

if(!window.location.href.match(/client_ip=.*?([^\&])/))
   return;

var ip = window.location.href.match(/client_ip=.*?([^\&])/)[0].replace('client_ip=','');


$("#ipClick").val(ip);

}
getUSERIP();

function getValue(){
location.href='/home/divya/html_docs/index.html';

}
</script>
</body>
</html>

我的index.html:

<!DOCTYPE html>
<meta charset='utf-8'>
<html>
  <head>
    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<script type="text/javascript" src="http://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>

<script type="text/javascript" src="https://raw.githubusercontent.com/mpryvkin/Plugins/master/pagination/simple_numbers_no_ellipses.js"></script>

<link rel='stylesheet' href='style.css'>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">


  <script>

  $(document).ready(function() {

$("#ip").val('');

    $('#example').DataTable( {
        "pagingType": "full_numbers"
    } );
} );

</script>

  </head>
  <body>

<div>
<form action="/home/divya/html_docs/click.html" method="get" >
Client_ip :<input type="text" id ="ip" name="client_ip" style="width: 600px;"/>
<div id="subDiv">
<button type="submit" value="Submit">Submit</button>
</div>
</div></br>

<table id="example" class="display" cellspacing="0" width="100%">
</table>

   <script>

  var tabulate = function (data,columns) {
var svg = d3.select('#ip').append("svg")
  var table = d3.select('#example')
    var thead = table.append('thead')
    var tbody = table.append('tbody')

    thead.append('tr')
      .selectAll('th')
        .data(columns)
        .enter()
      .append('th')
        .text(function (d) { return d })

    var rows = tbody.selectAll('tr')
        .data(data)
        .enter()
      .append('tr')

    var cells = rows.selectAll('td')
        .data(function(row) {
            return columns.map(function (column) {
                return { column: column, value: row[column] }
          })
      })
      .enter()
    .append('td')
   .text(function (d) { return d.value })
   .append("input")
   .attr("id","change")
   .attr("type", "checkbox")
   .style("float","left")
.on("click", function(d,i) { 

        var csv = $(':checkbox[id=change]:checked').map(function(){return $(this).parent().text();}).get().join(',');

        $('#ip').val(csv);

});

  return table;
}

d3.csv('some1.csv',function (data) {
    var columns = ['client_ip']
  tabulate(data,columns)
});
  </script>
  </body>
</html>

任何人都可以帮我解决这个问题...

2 个答案:

答案 0 :(得分:0)

在你的getValue()函数中,你需要返回res值。

答案 1 :(得分:0)

您为它创建了一个函数并将其放在click.html文件

function getUSERIP(){

if(!window.location.href.match(/client_ip=.*?([^\&]+)/))
   return;
var ip = window.location.href.match(/client_ip=.*?([^\&]+)/)[0].replace('client_ip=','');

$("#ipClick").val(ip);

}
getUSERIP();