<form>
<input type="search" id="searchInput" placeholder="Search...">
<button type="button" onclick="searchFunction()">Search</button>
</form>
<script>
function searchFunction() {
var searchText = document.getElementById('searchInput').value;
if (searchText) {
if (window.find && window.getSelection) {
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(searchText)) {
document.execCommand("HiliteColor", false, "yellow");
sel.collapseToEnd();
}
document.designMode = "off";
} else if (document.body.createTextRange) {
var textRange = document.body.createTextRange();
while (textRange.findText(searchText)) {
textRange.execCommand("BackColor", false, "yellow");
textRange.collapse(false);
}
}
}
}
</script>上一篇:图文切换嵌套图文列表
下一篇:照片墙滚动