打印

一起来玩玩javascript

一起来玩玩javascript

很多程序员不喜欢javascript,其实javascript是一门非常好玩的语言。
从今天开始,我们一起来玩玩js

一、会报警的字符串。
“Your computer is too SB sir!”,如何在网页上弹出这个警告?这是一个再初级的js程序员都会写的
复制内容到剪贴板
代码:
alert("“Your computer is too SB sir!”");
通过调用alert,把警告信息弹出,very easy!
警告信息是“被”弹出出来的,不是吗?被alert命令弹出!

我们的警告信息不高兴了,它想变被动为主动,主动说我要给你警告!像这样
复制内容到剪贴板
代码:
““Your computer is too SB sir!””.alert();
是的,主动警告。
如何做到呢?你需要下面的代码:
复制内容到剪贴板
代码:
<html>
    <head>
        <title>String self alert</title>
        <script type="text/javascript">
            String.prototype.alert = function() {
                alert(this);
            }

            "Your computer is too SB sir!".alert();
        </script>
    </head>
    <body>
    </body>
</html>
警告字符串有了自己的话筒,大声说alert!

enjoy!
First they ignore you, then they laugh at you, then they fight you, then you win.

TOP

一看就知道楼主不是做WEB出来的

TOP

不过辛苦楼主啦!这么基础功的帖子顶了

TOP

引用:
原帖由 macoo 于 2007-4-25 20:29 发表
一看就知道楼主不是做WEB出来的
何出此言?

另外,声明一下,这只是为了好玩,没有其它的,请不要谈实用或者意义:)
First they ignore you, then they laugh at you, then they fight you, then you win.

TOP