django finishing

front end

1. js each cycle

Distal loop needs, this method can make use of each

Copy the code
DIC = {var 'key1': 'VALUE1', 'key2': 'value2'}; 
var LIS = [ '. 1', '. 3', '2']; 
// each (variable, method) 
$ .each ( LIS, function (index, obj) { 
    the console.log (index, obj) 
}) 
// if the object is passed in a variable object (dictionary), then the method index, and value, respectively, and key value 
    // key1 VALUE1 
    key2 value2 // 
// If the incoming variable is an array of array (list), the index and the method are the index value and the corresponding value 
    // 0 '1' 
    @ 1 '3' 
    // 2 '2'
Copy the code

 2. Enter the quick access to content serializeArray ordinary label under the form tag

// serializeArray method may view the contents of a tag common form form input box, select the label not submitted 
RES = $ ( '# id_form') serializeArray ();. 
The console.log (RES)

Get the label content, namely, the value of the name and value

3. The three ways img src tag may be entered

  a. You can enter an absolute path directly

  b. enter url

  c. You can enter the picture binary files (FileRead)

Objects below to get a picture file is then rendered to the front-end input steps on the other img tags

Copy the code
// First, input a label, we want to get his file, you first need to get his js objects 
// Then, .file come up with an array of files, index 0 out file object 
var file_obj = $ ( 'input' ) [0] .file [0]; 
// file reader generating 
var = new new FileReader the FileReader (); 
// file object into the document reader readAsDataURL 
FileReader.readAsDataURL (file_obj); 
// for results 
res = fileReader .Result 
// RES into the src attribute of the img tag, you can render a picture

Guess you like

Origin www.cnblogs.com/duGD/p/11261885.html