我需要将此javascript代码放入jquery,但我对jquery没有太多经验

时间:2017-04-17 19:34:01

标签: javascript jquery html ajax xml

这个代码在JQuery中会是什么样子?我正在尝试读取xml文件 扔进一张桌子。加载该表后,我需要能够单击 从表中获取一行并从该行获取数据以执行另一个功能。 我已经意识到这对纯粹的javascript来说真的不可能..

function getWellDataXMLFile() {
    var well = new XMLHttpRequest();
  well.onreadystatechange = function() {
    if (well.readyState == 4 && well.status == 200) {
      searchWellData(well);
    }
  };
  well.open("GET", "welldata.xml", true);
  well.send();

}

function searchWellData(well) {

var i;
//get data as xml file
var xmldoc = well.responseXML;
//start table
var wellsearch = document.getElementById("wellSearch").value;
var table="<table id ='printWellData'><tr><th>Location</th><th>Depth</th><th>Perf Depth</th><th>Perf Zone</th><th>Well Stroke</th><th>Stroke Per Minute</th></tr>";
//process data by record
var x = xmldoc.getElementsByTagName("welldata");
var errorMessage = "Error, Well does not exist.";
  for (i = 0; i <x.length; i++) { 


    var wellLocation = x[i].getElementsByTagName("location")[0].childNodes[0].nodeValue;

    if(wellsearch === wellLocation.toString().trim().substring(0,2).toUpperCase()||(wellsearch === wellLocation.toString().trim().substring(0,3).toUpperCase())){
    var wellDepth = x[i].getElementsByTagName("welldepth")[0].childNodes[0].nodeValue;
    var perfDepth = x[i].getElementsByTagName("perfdepth")[0].childNodes[0].nodeValue;
    var perfZone = x[i].getElementsByTagName("perfzone")[0].childNodes[0].nodeValue;
    var wellStroke = x[i].getElementsByTagName("stroke")[0].childNodes[0].nodeValue;
    var strokePerMin = x[i].getElementsByTagName("strokepermin")[0].childNodes[0].nodeValue;

        table += "<tr><td>" +
        wellLocation +
        "</td><td>" +
        wellDepth + 
        "</td><td>" +
        perfDepth +
        "</td><td>"+
        perfZone +
        "</td><td>" +
        wellStroke +
        "</td><td>" +
        strokePerMin +
        "</td></tr>";
        document.getElementById("printWellData").innerHTML = table;

    }

  }



}

0 个答案:

没有答案