如何在 html 中实现自动文本搜索
How to implement Auto Text search in html?
我想向我的网页添加文本搜索。但我希望它自动搜索当用户输入文本而不单击"查找"按钮时。我想删除按钮并使其自动搜索
示例代码
function doSearch(text) {
if (window.find && window.getSelection) {
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(text)) {
document.getElementById("button").blur();
document.execCommand("HiliteColor", false, "yellow");
sel.collapseToEnd();
}
document.designMode = "off";
} else if (document.body.createTextRange) {
var textRange = document.body.createTextRange();
while (textRange.findText(text)) {
textRange.execCommand("BackColor", false, "yellow");
textRange.collapse(false);
}
}
}
<input type="text" id="search">
<input type="button" id="button" onmousedown="doSearch(document.getElementById('search').value)" value="Find">
<div id="content">
<p>Here is some searchable text with some lápices in it, and more lápices, and some <b>for<i>mat</i>t</b>ing</p>
</div>
<input type="text" id="search" onkeypress="doSearch(this.value)">
http://www.w3schools.com/jsref/event_onkeypress.asp
相关文章:
- 如何在文本搜索后返回long/lat
- 使用 CSS3 数据属性进行客户端文本搜索
- 谷歌地图API地理位置文本搜索地点详细信息
- 使用谷歌地图API和谷歌文本搜索进行地理定位
- 如何在 html 中实现自动文本搜索
- 放置 API 文本搜索与附近搜索
- 当前网页上的本地可见文本搜索
- Jquery文本搜索并对该文本执行某些操作
- jQuery:如何在文本搜索中只显示DOM的特定元素
- MongoDB在一个列表中检查多个regex匹配项以进行免费文本搜索
- 使用AND运算符进行Mongoose文本搜索
- 使用文本搜索并删除节点jquery
- jQuery移动文本/搜索更改事件的行为不同
- Angular自定义文本搜索过滤器顺序
- 实时文本搜索jquery,错误的选择器
- MongoDB文本搜索与周期
- 提高MongoDB的文本搜索性能
- 使用在文本框中输入的文本搜索复选框中的项
- 如何通过文本搜索返回JSON数组中项目的索引位置?
- 通过选项文本搜索选项索引