Jquery MDL就绪事件
正在页面加载时升级其组件,因此带有Jquery MDL就绪事件,jquery,javascript-events,material-design,autofocus,material-design-lite,Jquery,Javascript Events,Material Design,Autofocus,Material Design Lite,正在页面加载时升级其组件,因此带有自动聚焦属性的会失去焦点。我想在MDL完成重新招标后,对该输入设置一个焦点 我正在听一些pageready事件(): 既不使用$(document)也不使用$(document.body)或$(“.mdl布局”)选择器。 我在谷歌上搜索过一些类似的事件,但运气不好,我错过了什么吗? 当然,我可以使用setTimeout,但我认为这不应该是一个解决方案我相信您可以收听mdl componentupgraded事件: $('input#srch').bind('md
自动聚焦属性的
会失去焦点。我想在MDL完成重新招标后,对该输入设置一个焦点
我正在听一些pageready事件():
既不使用$(document)
也不使用$(document.body)
或$(“.mdl布局”)
选择器。
我在谷歌上搜索过一些类似的事件,但运气不好,我错过了什么吗?
当然,我可以使用setTimeout
,但我认为这不应该是一个解决方案我相信您可以收听mdl componentupgraded
事件:
$('input#srch').bind('mdl-componentupgraded', function(){console.log('ready')});
您可以在布局元素.mdl布局
上收听mdl componentupgraded
事件
$(document).ready(function() {
$('.mdl-layout').on('mdl-componentupgraded', function(e) {
if ($(e.target).hasClass('mdl-layout')) {
alert('ready');
}
});
});
在
上使用,而不是一个
。您的页面可能有多个正在升级的元素。通过使用one
您将只捕获第一次升级。启用时,由于事件冒泡,将多次调用处理程序。选中e.target
,对布局元素的特定升级作出反应
使用$(document).ready()
回调。等待DOM准备就绪,然后再将处理程序附加到其元素。否则,$('.mdl layout')
选择器可能不匹配,事件处理程序可能无法连接。使用firefox,mdl componentupgraded调用仅在我加载页面后进行,然后刷新页面。。。你知道为什么会这样吗?与铬合金配合使用效果良好
/* Check if the material design has finished the rendering */
var mdlLoaded = setInterval(function(){
if(typeof document.querySelector('.mdl-js-layout') !== 'undefined') init()
}, 100)
function init () {
clearInterval(mdlLoaded)
alert('ready')
}
/* Check if the material design has finished the rendering */
var mdlLoaded = setInterval(function(){
if(typeof document.querySelector('.mdl-js-layout') !== 'undefined') init()
}, 100)
function init () {
clearInterval(mdlLoaded)
alert('ready')
}