有一段代码prototype ,直接 在chrome 或是 firefox里不能执行
但是将其内容分别贴在
jsbin.com 网站后,却能得运行正常
是什么原因?求大师指点
代码如下 :<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.1/prototype.js">
</script>
<script type="text/javascript">
var checkBoxWatcher = Class.create();
checkBoxWatcher.prototype = {
initialize: function(chkBox, message){
this.chkbox = $(chkBox);
this.message = message;
this.chkbox.onclick = this.showMessage.bindAsEventListener(this);
},
showMessage: function(evt) {
alert(this.message + '(' + evt.type + ')');
}
};
var checkWatcher = new checkBoxWatcher('mybox', 'i\'m OK!');
</script>
</head><body>
<div id="mybox"> haha </div>
</body>
</html>
但是将其内容分别贴在
jsbin.com 网站后,却能得运行正常
是什么原因?求大师指点
代码如下 :<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.1/prototype.js">
</script>
<script type="text/javascript">
var checkBoxWatcher = Class.create();
checkBoxWatcher.prototype = {
initialize: function(chkBox, message){
this.chkbox = $(chkBox);
this.message = message;
this.chkbox.onclick = this.showMessage.bindAsEventListener(this);
},
showMessage: function(evt) {
alert(this.message + '(' + evt.type + ')');
}
};
var checkWatcher = new checkBoxWatcher('mybox', 'i\'m OK!');
</script>
</head><body>
<div id="mybox"> haha </div>
</body>
</html>
解决方案 »
- ext3.x+swfupload + struts1.2 上传文件的问题!
- 求JS中显示当前日期后30天的方法
- popup.js 使用
- javascript支持函数式编程的含义是什么?谁举个例子,谢谢。
- 求一个正则。关于取=号后的数据。
- 急:现在哪里可以下载JSVM优化的Ext for jsvm啊
- GB2312编码乱码的问题
- 请问: 在ascx里面写javascript要用到页面上的某个控件,要怎么找到呢 ?我是用document.getElementID()但是好像找不到
- 两个input框同步
- 两个JS之间有冲突,求解!js文件:Dialog.js和jquery.booklet.latest.js
- 友盟页面访问路径问题,类似组织结构图
- 新人有问题向大家请教,如何让页面在加载登陆页时,登陆框一直居中显示?
var Class={create:function(){return new Function();}}
var checkBoxWatcher = Class.create();
......
把这句代码加到前面就行了