Bra*_*cal 11 iframe jquery events loading
我有一些问题focus(function(){})和blur(function(){})被嵌套在一个动态加载的iframe中的脚本中..
下面是动态加载iframe的脚本标签WITHIN.我抛入脚本标记的任何事件都不起作用,像一个简单的事情$('input').click(function(){alert('fired')});甚至不会运行.我不确定发生了什么.
是的,jQuery被加载到头部的iframe中.
<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
$('.form .field-content').find('input, select, textarea').focus(function() {
$(this).closest('.field').addClass('focused');
});
$('.form .field-content').find('input, select, textarea').blur(function() {
$(this).closest('.field').removeClass('focused');
});
$('.form .field-content').find('input, select').keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
$(this).closest('.form').find('.button').first().click();
}
});
$('.form .button').focus(function() {
$(this).addClass('focused');
});
$('.form .button').blur(function() {
$(this).removeClass('focused');
});
// focus on first field
$('.form .field-content').find('input, select, textarea').first().focus();
});
// ]]>
</script>
Run Code Online (Sandbox Code Playgroud)
也许问题是 iframe 内容尚未加载,请尝试
$("#Your-Iframe-Id").load(function (){
// write your code here
});
Run Code Online (Sandbox Code Playgroud)