如何用逗号设置图像名称到hiddenfeild?

时间:2017-04-11 10:09:59

标签: jquery

我正在尝试将隐藏字段值设置为逗号分隔的图像名称与输入类型文件控件。我尝试过使用jQuery,



var idProjectTitle = document.getElementsByClassName("idProjectTitle");

           
           var path2 = "";
        for (var i = 0; i < idProjectTitle.length; i++) {
          
                path2 += idProjectTitle[i].files[0].name + ',';              
        }
            $('#hdProjectTitle').val(path2); /*Here is setting image names as hdfield value*/
&#13;
&#13;
&#13;

但发生错误&#39;无法读取属性&#39; name&#39;未定义的&#39;。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

你必须在#Import the library import pandas import itertools import bokeh import MySQLdb from bokeh.plotting import figure, output_file, show from bokeh.models import HoverTool TOOLS='hover' wells=['F1','F2','F3','F4','F5','F6','F7','F8','F9','F10','F11','F12','G1','G2','G3','G4','G5','G6','G7','G8','G9','G10','G11','G12'] p = figure(plot_width=800, plot_height=640,x_axis_type="datetime", tools=TOOLS) p.title.text = 'Click on legend entries to hide the corresponding lines' # Open database connection db = MySQLdb.connect("localhost","user","password","db" ) #pallete for the lines my_palette=bokeh.palettes.inferno(len(wells)) #create a statement to get the data for name, color in zip(wells,my_palette): stmnt='select date_time,col1,wells,test_value from db where wells="%s"'%(name) #creating dataframe df=pandas.read_sql(stmnt,con=db) p.scatter(df['date_time'], df['test_value'], line_width=2, color=color, alpha=0.8, legend=name,) #Inserting tool tip hover = p.select(dict(type=HoverTool)) hover.tooltips = [("Wells","@wells"),("Date","@%s"%(df['date_time'])),("Values","@%s"%(df['test_value']))] hover.mode = 'mouse' #Adding a legend p.legend.location = "top_right" output_file("interactive_legend.html", title="interactive_legend.py example") show(p) 函数里面这样做

file input on change
$('.idProjectTitle').change(function(){

var idProjectTitle = document.getElementsByClassName("idProjectTitle");

           
           var path2 = "";
           for (var i = 0; i < idProjectTitle.length; i++) 
           {

               if(idProjectTitle[i].files[0] != undefined)
               {
                  path2 += idProjectTitle[i].files[0].name + ',';  

                }            
            }

            $('#hdProjectTitle').val(path2);
            
            });

答案 1 :(得分:1)

试试这个。如果您只想添加现有文件,它应该解决。

    $('.idProjectTitle').change(function(){

    var idProjectTitle = document.getElementsByClassName("idProjectTitle");

               
               var path2 = "";
            for (var i = 0; i < idProjectTitle.length; i++) {
              if(idProjectTitle[i].files[0] != undefined){
                    path2 += idProjectTitle[i].files[0].name + ',';              
}
            }
                $('#hdProjectTitle').val(path2); /*Here is setting image names as hdfield value*/
            
            });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" name="file" multiple class="idProjectTitle" />

<input type="text" id="hdProjectTitle" name="hdProjectTitle" />