有一段代码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>
解决方案 »
- highcharts结合ajax绘图x轴时间 怎么设置?
- 把$换成jquery JS报出undefined is not a function错误
- js 回车提交表单问题,我是在img标签里加onclick 然后提交的 可是这样的话不能回车提交。请问高手如何解决
- 关于js调用qq进程的问题
- 请大家帮忙!
- 客户端javascript扩展ms的treeview节点问题,试验了好多方法都不行,急急急!!!
- Windows Media Player 10 的controls
- 在用DOM方法,修改、增加、删除文件节点后,如何保存问题?
- jsp传值给js的问题
- window.open
- 关于prototype问题请教
- JS里的switch怎么写?
<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 Class={create:function(){return new Function();}}
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>
<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>
</head><body>
<div id="mybox"> haha </div><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>
</body>
</html>