Javascript 模块化JS:如何传递变量和事件
我有这个JS代码:Javascript 模块化JS:如何传递变量和事件,javascript,ecmascript-5,es5-shim,Javascript,Ecmascript 5,Es5 Shim,我有这个JS代码: const getData = { // set vars start_date: <?php echo $start_ts; ?>, end_date: <?php echo $stop_ts; ?>, init: function() { this.cacheDom();
const getData = {
// set vars
start_date: <?php echo $start_ts; ?>,
end_date: <?php echo $stop_ts; ?>,
init: function() {
this.cacheDom();
this.bindEvents();
},
cacheDom: function() {
this.form = form;
this.show = show;
},
bindEvents: function() {
this.show.click(this.sendData(this.start_date, this.end_date));
},
sendData: function(sdate, edate, e){
e.preventDefault();
// this.form.submit();
console.log(sdate);
console.log(edate);
},
render: function() {}
}
// run object
getData.init();
const getData={
//设置变量
开始日期:,
结束日期:,
init:function(){
this.cacheDom();
这是bindEvents();
},
cacheDom:function(){
this.form=形式;
show=show;
},
bindEvents:function(){
this.show.click(this.sendData(this.start\u日期,this.end\u日期));
},
sendData:函数(sdate、edate、e){
e、 预防默认值();
//这个.form.submit();
控制台日志(sdate);
控制台日志(edate);
},
呈现:函数(){}
}
//运行对象
getData.init();
我试图通过单击事件传递this.start\u date
和this.end\u date
。尝试了几种不同的方法(你看到的就是其中之一)
请帮助我传递带有变量的click事件
bindEvents: function() {
this.show.onclick = this.sendData.bind(this, this.start_date, this.end_date);
},
click
模拟单击按钮,而不是附加事件处理程序(这将适用于jquery对象,但不适用于dom元素)