存在这是我的HTML代码:阅读阵列txt文件,并检查变量输入数组
<?php
$filename = 'codes.txt';
$data = file($filename);
foreach($data as $key => $val){
$array[] = $val;
}
?>
<form id="checkinput" action="#">
<input class="zipcodes" name="zipcodes" value="" type="text">
<input class="zip-sub" type="button" value="Continue" id="submit">
</form>
氏是jQuery代码:
jQuery(document).ready(function() {
jQuery('.zip-sub').click(function() {
var zip = jQuery('.zipcodes').val();
var zipcodelist = <?php echo json_encode($array); ?>;
if(jQuery.inArray(zip, zipcodelist) != -1){
alert('value is .txt file !');
} else {
alert('value is not .txt file');
}
});
});
这在某些变量的类型。 txt文件:
12345
23456
56789
我需要的:当我填写输入字段我可以CHEC数据k其变量是否在.txt文件中
它与数组中的最后一个变量一起工作,根本没有。我不知道代码错在哪里?请帮助。 在此先感谢!
我不是什么应该清楚在这里发生? – jonmrich
只是编辑我需要的东西。谢谢 ! – OhIWill
你能解释一下这是什么意思:“它与数组中的最后一个变量一起工作,根本就没有。” – jonmrich