1

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

谢谢

4

1 回答 1

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>");
        }
    }
});
于 2012-09-19T13:11:55.153 回答