Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过jQuery将id以逗号分隔的JavaScript函数添加到元素的ontouchend属性中?_Jquery - Fatal编程技术网

如何通过jQuery将id以逗号分隔的JavaScript函数添加到元素的ontouchend属性中?

如何通过jQuery将id以逗号分隔的JavaScript函数添加到元素的ontouchend属性中?,jquery,Jquery,我有一个JavaScript函数,其中有四个逗号分隔的id function expCountDown(id1, id2, id3, id4) 目前,我正试图通过jQuery将包含JavaScript函数的ontouchend属性附加到元素中。。。。。。。它不起作用了 $("#gaskup1_cash").bind("touchstart", function(){ $(".dialogOKtext").attr("ontouchend": "expCountDown('gaskup1_che

我有一个JavaScript函数,其中有四个逗号分隔的id

function expCountDown(id1, id2, id3, id4)
目前,我正试图通过jQuery将包含JavaScript函数的ontouchend属性附加到元素中。。。。。。。它不起作用了

$("#gaskup1_cash").bind("touchstart", function(){
$(".dialogOKtext").attr("ontouchend": "expCountDown('gaskup1_check', 'gaskup1_count', 'gaskup1_expired', 'gaskup1')");
});
我已经成功地用JavaScript函数实现了这一点,它只有一个id或者没有id,所以我想这是由于函数中的逗号造成的


我知道这是一种可怕的方式。但仅仅为了论证,这可能吗?无论如何,如何/为什么?

我不确定绑定touchend事件是否正是您想要的。如果是这样的话,你应该按照下面的步骤来做

$(".dialogOKtext").on("touchend", function(){
  expCountDown('gaskup1_check', 'gaskup1_count', 'gaskup1_expired', 'gaskup1');
});

请注意,从jQuery 1.7开始,绑定事件处理程序的首选方法是。

您是如何认识到这样做会起作用的?好的,感谢您提供的绑定信息:但是,我遇到的问题不是ontouchend事件的绑定,而是使用dialogOKtext类向元素添加ontouchend属性。