2015-11-03 48 views
0

我在使用rails 4和turbolinks我的项目上使用更改功能。它在我的网页浏览器中工作正常,但是当我在Nexus 7 Android 5.1.1上测试时,它不起作用。 以下是我的代码。jQuery的变化事件不适用于铬联系7

_form.html.erb

<%= image_attributes.file_field :photo, :style => "display:none", :class => "update-file", :data => {:thumbnail => image_attributes.index}, accept: 'image/png,image/jpeg' %> 

common.js

$(document.body).on('change', '.update-file', function(event) { 
return console.log('1'); 
}); 

回答

0

change没有正确触发,你可以尝试另外使用一个不同的事件像blur

$(document.body).on('change blur', '.update-file', function(event) { 
    return console.log('1'); 
}); 
+0

我试过你的代码,它也不适用于nexus 7 chrome。它可以在其他设备和我的系统浏览器上正常工作。 –

+0

对不起,听到...如果在nexus浏览器上有任何错误消息,请参阅下面的内容会很有趣。你可以看到它们,如果你通过adb将你的连接线连接到你的电脑上,就可以在你的电脑上打开Chrome浏览器,然后你可以在chrome的地址栏中输入'chrome:// inspect'来看看到底发生了什么。这里是一个解释:https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging –

+0

我使用的是浏览器,它不会在控制台上显示任何错误。我尝试过尝试不同的选择器,即 $(document).on('change','.update-file',function(event){console.log('1');}); $(document).on('change blur','.update-file',function(event){console.log('1');}); $(document.body).on('change blur','.update-file',function(event){console.log('1');}); ('。update-file')。on('change',function(event){console.log('1');}); 所有这些在其他设计上工作正常,但不在连接7上。 –