我正在尝试使用文本文件中的值填充下拉列表。我有以下代码,但是,我在下拉列表中没有得到任何内容。谁能帮我?
这是我的 jquery 和 HTML 下拉列表代码:
<script>
$filename = 'pytxt.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
echo '<select name="value" id="value">';
foreach($eachlines as $lines){
echo "<option>($lines)</option>";
}
echo '</select>';
</script>
</head>
<body>
<div id="page-wrap">
<h1>Pulls from text files</h1>
<select id="value">
<option selected value="base">Please Select</option>
<option value="1"></option>
<option value="2"></option>
</select>
</div>
</body>
1.您当前的代码页必须是.php
page.(页面的扩展名需要是.php
)
2.更改代码如下:-
<?php
//remove <script></script> and add php start and close tag
//comment these two lines when code started working fine
error_reporting(E_ALL);
ini_set('display_errors',1);
$filename = 'pytxt.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<body>
<div id="page-wrap">
<h1>Pulls from text files</h1>
<select id="value">
<option selected value="base">Please Select</option>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</div>
</body>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)