doubiao7410 2016-10-13 01:42
浏览 68
已采纳

读取数组中的.txt文件,检查数组中是否存在变量输入

This is my HTML code:

<?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>

Thi is jQuery code:

    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');
        }
    });

});

This is type of some variable in .txt file:

12345
23456
56789

What i need: when i fill data in input field i can check its in variable in .txt file or not

Its working with last variable in array, not at all. I dont know where's the code is wrong ? Pls help. Thanks in advance !

  • 写回答

1条回答 默认 最新

  • douewei1665 2016-10-13 02:08
    关注

    Fix your .txt file to look more like this:

    12345,23456,56789

    Don't add in line breaks like this:

    12345, 23456, 56789

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳