使用jquery从csv导入ph值到html多选框

时间:2012-09-19 12:56:17

标签: jquery html csv

我想将包含电话号码的csv文件导入到html多选框中。用jquery或ajax可以吗?请任何人帮忙吗?

由于

1 个答案:

答案 0 :(得分:2)

这样的事情:

//jquery ajax function, calls a file (url), if it succeds, the "success" happens, "data" is the contents of the file
$.ajax({
    url: 'path_to_your_file',
    success: function(data) {
        //splitting the data by commas (i presume that with csv you mean comma seperated values file)
        var splitData=data.split(",");
        //looping through the data
        for(pn in splitData){
            //current phone number is stored in "pn", appending a new option with value of the current phone number to the multiple select box with id "select_id"
            $('#select_id').append("<option value=\""+pn+"\">"+pn+"</option>");
        }
    }
});