【发布时间】: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