How to grab piece of html from external html and place it on current

坚强是说给别人听的谎言 提交于 2019-12-08 10:37:45

问题


This code works perfectly ok, but what if I need the searched item be in another file format, say .txt?

It may happen if my search database becomes very large, so I want jQuery to take the input, search for it in another file and if jQuery finds it, show that div on the current page.

Is this possible?

<script>
    $('#me').change(function() {
        $('div:contains('+ $.trim(this.value) + ')').css('color','red');
    });
</script>

I've found this on stackoverflow, but couldn't recognize how to make them work together

var HTML_FILE_URL = '/whatever/html/file.html';
$(document).ready(function() {
    $.get(HTML_FILE_URL, function(data) {
        var fileDom = $(data);
        fileDom.find('h2').each(function() {
            alert($(this).text());
        }); 
    }); 
});

回答1:


Try this one:

$("#divWhereTheContentShouldBeWritten").load("path/externalFile");


来源:https://stackoverflow.com/questions/11907028/how-to-grab-piece-of-html-from-external-html-and-place-it-on-current

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!