发布网友 发布时间:2022-04-23 09:53
共1个回答
热心网友 时间:2022-04-23 08:30
<html>
<script>
function searchWords() {
var words = document.getElementById('search').value;
if (words != '') {
var innerHTML = document.body.innerHTML;
if (innerHTML.indexOf(words) != -1) {
alert('找到了');
if (words == '123') {
alert('123不作操作');
} else if (words == '456') {
alert('456跳转页面');
window.location.href = 'http://www.baidu.com';
} else if (words == '567') {
alert('567替换内容');
document.body.innerHTML = innerHTML.replace(new RegExp(/(567)/g),'7');
}
}
}
}
</script>
<body>
<div>1234567abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
<div><input id='search' type='text' placeholder='请输入查询字符' /><button onclick='searchWords();'>查询</button></div>
</body>
</html>