【问题标题】:Cannot display value of php to html input form无法将 php 的值显示到 html 输入表单
【发布时间】:2017-03-08 09:38:37
【问题描述】:

我想在 html 上显示数组值。数组值来自 php。

选择选项有效,但不显示下一个字符串值。

喜欢这张照片...

(它不起作用“获得价值”..我认为....)

源代码在这里...

PHP -

<?php
   $arr[0]="11.1.35.132";
?>

php 代码具有.. 只有数组值。并且该值被发布到 HTML。

HTML -

    <html>
<head>
<link rel="stylesheet" type="text/css" href="../css/main.css">
<script type="text/javascript">

function getR() {
    document.forms['save']['cnt_mme'].value = "<?php echo count($arr); ?>";
    document.forms['save']['mmeremoteip'].value = <?php echo json_encode($arr[0]); ?>;
}
</script>
</head>
<body onLoad="getR();">
<form name="save" method="post">
<h1>TEST</h1>
<table>

<tr><td>No. of IP</td>
<td id="cnt_mme">
<script>
  var mmeip = "<?php echo count($arr); ?>";
  var opt = document.getElementById("cnt_mme");
  var html="<select size=\"1\"";

  for(i = 0; i < mmeip; i++) {
      html += "<option value=\"" + i + "\">" + i +"</option>";
  }
  html + "</select></td>";
  opt.innerHTML = html;
</script>
  <tr>
   <td class="param">Remote IP</td>
   <td><input type="text" class="inputParam" size="20" maxlength="15" name="mmeremoteip" id="MME REMOTE IP"></td>
  </tr>
</tr>

</table>
</body>
</html>

并且查看源是 ....

   <head>
<link rel="stylesheet" type="text/css" href="../css/main.css">
<script type="text/javascript">

function getR() {
    document.forms['save']['cnt_mme'].value = "3";
    document.forms['save']['mmeremoteip'].value = "10.1.35.31";
}
</script>
</head>
<body onLoad="getR();">
<form name="save" method="post">
<h1>TEST</h1>
<table>

<tr><td>No. of MME Remote IP</td>
<td id="cnt_mme">
<script>
  var mmeip = "3";
  var opt = document.getElementById("cnt_mme");
  var html="<select size=\"1\"";

  for(i = 0; i < mmeip; i++) {
      html += "<option value=\"" + i + "\">" + i +"</option>";
  }
  html + "</select></td>";
  opt.innerHTML = html;
</script>
  <tr>
   <td class="param">MME Remote IP</td>
   <td><input type="text" class="inputParam" size="20" maxlength="15" name="mmeremoteip" id="MME REMOTE IP"></td>
  </tr>
</tr>

</table>
</body>
</html>

我认为 getR() 函数有问题。具体我不知道。

【问题讨论】:

  • 你的关闭form标签在哪里

标签: javascript php jquery html arrays


【解决方案1】:
 document.forms['save']['mmeremoteip'].value = <?php echo $arr[0]; ?>;

不要编码,没必要。

【讨论】:

    【解决方案2】:

    此处选择标记未关闭,并尝试在您正在脚本中访问的数组中添加更多值。

    例如添加

    <?php
    $arr=array();
    
       $arr[0]="11.1.35.132";
        $arr[1]="11.1.35.133";
         $arr[2]="11.1.35.135";
    
    ?>
    

    添加更改关闭html中的选择标签:

    <script>
      var mmeip = "<?php echo count($arr); ?>";
      var opt = document.getElementById("cnt_mme");
      alert(mmeip)
      var html="<select size=\"1\">";
    
      for(var i = 0; i < mmeip; i++) {
          html += "<option value="+ i + ">" + i +"</option>";
      }
      html + "</select></td>";
      opt.innerHTML = html;
    </script>
    

    您将获得具有 0,1,2 选项值的选项列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      • 2019-03-12
      • 2011-08-23
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多