function test(){
....
}
test.prototype.a()= function(){
var container = $("#table");
container.append("<span onclick='在这里如何写b方法'></span>");
}test..prototype.b()= function(){
...
}
第6行该怎么写呢,在a方法中调用b方法是用this.b(),但我现在是在append后的html中,onclick后才调用,如果直接写成onclick='+ this.b() +';这样不用点击,直接就运行了,是不对的,该怎么写呢,我现在是用实例名写死的,如
var mytest=new test();
onclick就写死了:
onclick="mytest.b()";,但这样写死了不太好吧,如果非要写死的话,请问在a方法中,如何得到实例的名称,也就是mytest
解决方案 »
- 有什么库可实现图标的拖放并组成一个流程?
- js中的ckeditor应用!!高手来看看呀!!!!
- tablesorter 中文 排序
- 谁能提供一下php在线订单项目,界面要求用extjs实现的报价
- IE 弹出一个要求输入用户名、密码的对话框,用Javascript如何实现??
- js跨域怎样解决:window.parent.func()怎样实现跨域?
- 请教达人用JS在服务器上怎么读写文本
- 同样3条的response.write,居然一条执行,2条不执行
- 求元素总数
- 请教,关于js预防暗弹的问题,感谢
- 网页中可能存在一个对象,并且只知道该对象的名字(字符串),那么如何访问该对象?
- 求JS全国学校列表联动菜单或数据
var container = $("#table");
container.append("<span></span>");
$("#table span").click(function(){//你改一下选择器,看怎样能匹配到刚才添加的span
//这里写方法
});
// 换个思维 把主导元素放到前面
<!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" />
<script src="jquery-1.3.2.js"></script>
<title>无标题文档</title>
</head><body>
<div id="table" style="width:100px;height:100px;border:1px solid red"></div>
<script type="text/javascript">
<!--
function test(){}
test.prototype.a= function(){
var _this = this;
var container = $("#table");
$("<span style='width:30px;height:20px;background-color:blue'>Span</span>").appendTo(container).click(function(){
_this.b();
});
}test.prototype.b= function(){
alert('b方法');
}
var T = new test();
T.a();
//-->
</script>
</body>
</html>