jquery移动触发器('create')方法不适用于iframe [英] jquery mobile trigger('create') method doesn't work with iframe

查看:102
本文介绍了jquery移动触发器('create')方法不适用于iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将.trigger('create')方法调用到iframe内容时,它不起作用,并且css类不应用于input:text元素。但是当我为iframe外的html内容调用.trigger('create')方法时,它可以正常工作

When I try to call .trigger('create') method to iframe contents, it does not work and css classes are not applied to input:text elements. but when I call .trigger('create') method for html content outside the iframe, it works

请转到此链接'here'并点击加载移动视图

please go to this link 'here' on jsfiddle and click on "load mobile view"

javascript code

javascript code

$('#mobile_view').contents().find('body').append("<div id='fbm_mob_menu'></div>");

$("#load_mobileview").click(function(){
    var content = ' <form class="fbm_contactform">\
    <div>Contact Us</div>\
    <div data-role="fieldcontain"><label for="name" >Name</label>\
    <input name="name" type="text" class="m-field" /></div>\
    <div data-role="fieldcontain"><label for="email">Email</label>\
    <input name="email" type="text" class="m-field" /></div>\
    <div data-role="fieldcontain"><label >Message</label>\
    <input name="message" type="text" class="m-field" /></div>\
    <input name="submitButton" type="submit" class="m-field" value="Send Message"  /></div>\
    </form> ';
$("#mobile_view").contents().find("#fbm_mob_menu").before(content);
$("#mobile_view").contents().find(".fbm_contactform").trigger("create");      
});

html代码

<a href="javascript:void(0)" id="load_mobileview" >load mobile view </a>
<iframe id="mobile_view"></iframe>
<div id="test"></div>


推荐答案

我可以通过在里面写一个javascript函数来解决这个问题iframe中。并从iframe调用该函数。

I could solve this problem by writing a javascript function inside iframe. and calling that function outside from the iframe.

在iFrame中

<script>
window.trigerCreate =function(){$(".fbm_contactform").trigger("create");}
</script>

父母

window.frames[0].trigerCreate();

这篇关于jquery移动触发器('create')方法不适用于iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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