问题
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