jQuery .on('click',..不会在safari中触发 [英] jQuery .on('click',.. does not trigger in safari

查看:357
本文介绍了jQuery .on('click',..不会在safari中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些图标动态添加到html表。其中一个是垃圾桶。当它被点击时,该行应该被删除。

I have these icons which are added dynamically to a html table. One of them is a trashcan. When it gets clicked the row should be deleted.

在开发期间,我在Firefox,Chrome和IE中测试它,它都像一个魅力。但现在有一个Safari用户注意到点击没有在Safari中被触发。
我下载并安装了最新版本的Safari for Windows来检查自己,确实没有什么事情发生在点击垃圾桶图标。

During development I tested it in Firefox, Chrome and IE and it all worked like a charm. But now there was a Safari user who noticed the click isn't triggered in Safari at all. I downloaded and installed the latest version of Safari for Windows to check myself and indeed nothing happens when clicking the trashcan icon.

奇怪的是,

它们都使用.on()和.off()。 (一些只是一个.click())。

They all use the .on() and .off(). (some are just a .click() ).

我的代码:

/**
 * Delete row from html table 
 */
$(document).on('click', '.deleteRow', function() {
    $('#row_' + $(this).attr('id').substr(4)).remove();
});

正如你可以看到的,没有真正复杂的jQuery代码。
有人知道为什么它可以在Firefox,Chrome和IE中使用,而它不在Safari中?

As you can see not really complicated jQuery code. Does anyone know why it works in Firefox, Chrome AND IE while it doesn't in Safari ?

编辑:
此外,我注意到另一个在Safari中的奇怪行为。在CSS中,我使光标成为一个指针。再次所有浏览器,但Safari正确添加CSS规则。
.deleteRow类的标签是< i> 标签..

/ p>

html = '<tr class="rowDomain" id="row_'+domain+'_'+ext+'">';
html += '<td class="get"><input type="hidden" name="hdnDomains[]" value="'+domain+'_'+ext+'_'+a+'_'+term+'_'+data.price+'" />'+domain+'.'+ext+' '+stars+'</td>';
html += '<td class="'+a+'">'+b+'</td>';
html += '<td>'+term+' jaar</td><td>&euro; '+(parseFloat(data.price).toFixed(2)).toString().replace('.',',')+'</td>';
html += '<td><i class="deleteRow icon-trash" id="btn_'+domain+'_'+ext+'" title="Verwijder domein uit selectie."></i></td>';
html += '</tr>';
$('#tblDomains').append(html);

上面是添加到我的< table& / code>每次用户单击按钮。
该图标位于最后的< td> 标记中。

The above is the HTML which gets added to my <table> each time a user clicks a button. The icon is in the last <td> tag.

推荐答案

我找到了一个解决方案。它和我使用的标签类型有关。
如果我在< i> 标签的背景上添加一种颜色,它会工作。

I found a solution. It had something to do with the type of tag I used I guess. If I add a color to the background of the <i> tag it works.

所以在CSS我做了:

.deleteRow {background-color:rgba(255,255,255,0.1);}

现在,游标是一个指针,点击处理程序可以正常工作。

Now the cursor IS a pointer and the click handler does its work.

不知道为什么,虽然...

Don't know about the why though...

这篇关于jQuery .on('click',..不会在safari中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆