我想在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>
和view-source是....
<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()函数有问题。我不确切地知道。
答案 0 :(得分:0)
document.forms['save']['mmeremoteip'].value = <?php echo $arr[0]; ?>;
不要编码,没有必要。
答案 1 :(得分:0)
此处select标签未关闭,并尝试在您正在脚本中访问的数组中添加更多值。
例如add
<?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选项值的选项列表。