Read data in HTML object tag

前端 未结 2 1399
春和景丽
春和景丽 2021-01-03 03:14

I have a text file stored on the server and an object in HTML like this:


         


        
2条回答
  •  天命终不由人
    2021-01-03 03:51

    I created a simple function and button as an example. Just copy the html and js code and it should work for you. Just make sure you create the appropriate txt or html file for the object to import.

    function getObjectData()
    {
        //alert("getObjectData");
        
        var myData = "";
        var object = document.getElementById("data");
        
        //get data inside object data
        var myData = object.contentDocument.body.childNodes[0].innerHTML;
    
        alert("myData => " + myData + " <= myData" );
    }
    #data{
        height: 36px;
        border: solid 1px red;
        /*overflow: hidden;*/
    }

提交回复
热议问题