我可以把它变成外部脚本吗?
<center>
Users online:
<blink>
<sup>
<form>
<TABLE style="background-color:white" border="2">
<TD><div id="text"></div></TD>
</TABLE>
</form>
</sup>
</blink>
</center>
<script type="text/javascript">
Function.prototype.allowSleep = function(n) {
var i, f;
if (!/^[$\w]+$/.test(n)) return;
i = 0;
f = this.toString().replace(/sleep\((.*?)\);/g , function(f,t) {i++; return n+".f"+i+" = function() {"+n+".func"+i+"();};\nsleep("+t+","+n+".f"+i+");\n"+(i==1?"":"}\n")+n+".func" + i +" = function() {";});
eval(n+'='+f+'\n}');
}
sleep = function(t,f) {
if (f === undefined) return;
setTimeout(f,t);
}
afunc = function() {
document.getElementById('text').innerHTML = '1';
sleep(2000);
document.getElementById('text').innerHTML = '2';
sleep(2030);
document.getElementById('text').innerHTML = '3';
}
afunc.allowSleep('afunc'); // comment
afunc();
</script>
我保存为.js,但我在第2行收到错误...
什么是.js以及如何制作它们?的xD
我只是希望能够隐藏我的代码
我是否必须点击按钮才能显示此内容或是否会显示在页面上?
答案 0 :(得分:1)
您无法在.js文件中保存html,只需将以下部分保存在您的。 js并包含它:
<script type="text/javascript">
Function.prototype.allowSleep = function(n) {
var i, f;
if (!/^[$\w]+$/.test(n)) return;
i = 0;
f = this.toString().replace(/sleep\((.*?)\);/g , function(f,t) {i++; return n+".f"+i+" = function() {"+n+".func"+i+"();};\nsleep("+t+","+n+".f"+i+");\n"+(i==1?"":"}\n")+n+".func" + i +" = function() {";});
eval(n+'='+f+'\n}');
}
sleep = function(t,f) {
if (f === undefined) return;
setTimeout(f,t);
}
afunc = function() {
document.getElementById('text').innerHTML = '1';
sleep(2000);
document.getElementById('text').innerHTML = '2';
sleep(2030);
document.getElementById('text').innerHTML = '3';
}
afunc.allowSleep('afunc'); // comment
afunc();
</script>