我有200个html文件,我必须隐藏电话号码,直到我们点击一个文本,所以我需要改变所有的文件内容使用像GrepWin这样的工具。我可以使用这段代码做到这一点,但问题是,对于同一页面中具有相同内容的所有位置,都需要更改函数名称和id。因此,这一行在同一文件中出现了多次:
<p>
<b>Contact data:
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "0316 301 958";} .
</script>
<button id="demo" onclick="myFunction()">Show the number</button>
<p>
<b>Contact data:
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "0316 301 958";} .
</script>
<button id="demo" onclick="myFunction()">Show the number
</button>我需要不同的解决方案来改变他们在所有的html文件,但显示的数字(这是相同的所有)。此时只显示一个数字http://jsfiddle.net/qyzkfush/。我可以手动编辑函数名称和按钮id,但更改200个文件的内容将花费我很长时间,每个文件中有许多位置。我需要使用GrepWin来搜索所有文件的代码并替换它。
发布于 2019-01-29 23:53:07
如果你真的必须这样做,你可以运行以下命令:
function myFunction(e, phoneNumber) {
e.innerText = phoneNumber;
}<p><b>Contact data:
<button id="demo" onclick="myFunction(this, '0316 301 958')">Show the number</button>
<p><b>Contact data:
<button id="demo" onclick="myFunction(this, '0316 301 957')">Show the number</button>
我只会用这个作为快速修复,我会和客户谈一谈如何使内容动态化。
https://stackoverflow.com/questions/54424302
复制相似问题