在嵌套在动态加载的iframe中的脚本中,我有一些焦点(function(){})和blur(function(){})的问题.
以下是动态加载iframe的脚本标签.任何事件我扔入脚本标记是不工作,简单的东西,如$(‘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,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,textarea').first().focus();
});
// ]]>
</script>
解决方法
也许问题是iframe的内容没有加载,试试看
$("#Your-Iframe-Id").load(function (){
// write your code here
});