[英]Cannot display value of php to html input form
我想在html上显示数组值。 数组值来自php。
select选项正在运行,但是不显示下一个字符串值。
喜欢这张照片
(“获取价值”是行不通的。
源代码在这里...
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()函数有问题。 我不知道
document.forms['save']['mmeremoteip'].value = <?php echo $arr[0]; ?>;
不用编码,没有必要。
在这里,select标记未关闭,并尝试在脚本中访问的数组中添加更多值。
例如添加
<?php
$arr=array();
$arr[0]="11.1.35.132";
$arr[1]="11.1.35.133";
$arr[2]="11.1.35.135";
?>
添加更改,关闭html中的select标签:
<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选项值的选项列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.