0
function sort(type) {
//EMPTY FUNCTION IS CALLED HERE FOR REMOVING ALL PREVIOUSLY CREATED CHILD DIVS
$("#parentDiv").empty();
$.get("http://www.omdbapi.com/?s=Batman&page=2", ({ Search }) => {
Search.sort((a, b) => a[type] > b[type]);
console.log(`Sorted by: ${type}`);
console.log("movies are displayed!!");
var i;
Loop從這裏開始創建div元素。當第二次調用該函數時,子div再次創建
for(i=0;i<Search.length;i++){
var title=Search[i].Title;
var year=Search[i].Year;
父div包含h2和p存在的子div。
var parentDiv=document.createElement("div");
parentDiv.setAttribute("id","parentDiv");
parentDiv.setAttribute("id","childDiv");
孩子的div和h2的和對的決策和追加到孩子的div從這裏開始
var childDiv=document.createElement("div");
var movieElement=document.createElement("h2");
movieElement.setAttribute("id","moviename");
var yearElement=document.createElement("p");
yearElement.setAttribute("id","year");
childDiv.appendChild(movieElement);
childDiv.appendChild(yearElement);
parentDiv.appendChild(childDiv);
document.body.appendChild(parentDiv);
//document.getElementsByTagName("h2")[i].innerHTML="<b>" + title + "</b><br>";
//document.getElementsByTagName("p")[i].innerHTML= year + "<br>"; }
});
}
當這個函數被調用第二次孩子的div再次創造雖然我首先聲明爲空(在第二行排序函數中)父div中的元素,然後從開始創建子div。
function show(){
var z=document.getElementById("sortOrder").value;
sort(z);
//sort(Year)
//sort(title)
};
無那沒用 –