从页面中查找长度为4的文本
Find text of length 4 from page
我想搜索页面上所有长度为4的单词或文本,并将其替换为使用regex 的函数返回的其他文本
$("#changeRandom").click(function() {
$("body").children().each(function() {
$(this).text($(this).text().replace(/([a-zA-Z]){4}/g,"hello"));
});
});
您不需要在这里循环或jQuery,它可以简单地用Js完成。但是,从您的代码中可以明显看出您对jQuery的偏好,您可以通过3个简单的步骤来完成这项工作:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network. Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network.Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network.</p>
<button onclick="replaceFunction()">Replace overflow with exchange</button>
<script>
function replaceFunction() {
var repWith ="exchange";
var content = $("body").html();
var result = content.replace(/overflow/gi, repWith);
$("body").html(result);
}
</script>
相关文章:
- GTM每隔5秒在页面上查找文本
- Javascript文本框-查找最低的输入和填充
- 查找已提交的文本区域数
- jquery在元素中查找文本节点,并使用标记进行连接和包装
- 从页面中查找长度为4的文本
- 原型JS查找跨度并替换文本
- jQuery在iFrame Src中查找和替换文本
- 在UIWebView中查找并突出显示带变音符号的阿拉伯语文本
- 正在查找最后一次出现的文本
- 使用 Selenium 在 IE9 浏览器中查找 PDF 文本
- 在其他网站上查找/着色/标记文本
- 单击已连接的可排序项时查找列表文本
- 在td旁边的HTML表中查找td文本
- JQuery 按文本查找 LI,按类查找 UL
- 根据文本查找数组中的项
- 如何避免/跳过CKEDITOR 4.0中隐藏/未显示内容中的文本查找
- 如何根据文本查找HTML元素,然后分配ID
- 使用jquery通过文本查找TH对象(表头),而无需遍历表的所有TH's
- 通过a列中包含的文本查找表的第一行,并选择同一行中的B列
- 如何使用量角器按文本查找和单击表元素