如何从外部html中获取一段html并将其放在当前位置 [英] How to grab piece of html from external html and place it on current
本文介绍了如何从外部html中获取一段html并将其放在当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码完全可以正常工作,但是如果我需要搜索的项目是另一种文件格式,比如 .txt
?
This code works perfectly ok, but what if I need the searched item be in another file format, say .txt
?
如果我的搜索数据库变得非常大,可能会发生这种情况,所以我希望jQuery接受输入,在另一个文件中搜索它,如果jQuery找到它,请在当前页面上显示该div。
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.
这可能吗?
<script>
$('#me').change(function() {
$('div:contains('+ $.trim(this.value) + ')').css('color','red');
});
</script>
我在stackoverflow上找到了这个,但是无法识别如何让它们一起工作
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());
});
});
});
推荐答案
试试这个:
Try this one:
$("#divWhereTheContentShouldBeWritten").load("path/externalFile");
这篇关于如何从外部html中获取一段html并将其放在当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文