我正在制作一个 phonegap 程序,我想使用一个.on('tap')
事件而不是onClick="blah(param1,param2)"
因为 400 毫秒的延迟。我想要做的是给一个“可点击”项目列表一个“button1”类,并为每个项目给它一个data-meth="dosomething3()"
,然后在点击某物时检索它。到目前为止,我的示例没有使用点击,而是点击。
<script>
$(document).ready(function() {
console.log('document ready');
$(".button1").on('click', function(e){ //this will changed to 'tap' eventually
e.preventDefault();
console.log("logged click");
var tempp=$(this).data("meth");
alert(tempp);
tempp; // thought this would call the function as it is written in the data-meth value but it doesn't
});
});
function dosomething(){
console.log('dosomething called');
}
function dosomething(var1,var2){
alert('hello:' +var1+' just showing var2'+var2);
}
</script>
My simple html is
<ul>
<li style="text-align:center" class="button1" data-meth="dosomething()" >One</li>
<li style="text-align:center" class="button1" data-meth="dosomething2(var1,var2)">Two</li>
<li style="text-align:center" class="button1" data-meth="dosomething3()">Three</li>
</ul>
我如何获取并调用基于函数的函数或存储在 data-meth 值中的内容?