动态调用fancybox
我想动态调用 fancybox 来加载 iframe。 iframe 的 URL 将由表单上的一些元素组成。我一直在使用类似的东西,它可以工作:
<!--***************************************************************-->
<!--this allows fancybox to be called using a dynamic link-->
<div id="hidden_clicker" style="display:none">
<a class="various fancybox.iframe" id="hiddenclicker" href="http://whatever.com" >Hidden Clicker</a>
</div>
<!--***************************************************************-->
然后是脚本:
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'elastic',
closeEffect : 'none'
});
});
function callBoxFancy(my_href) {
var j1 = document.getElementById("hiddenclicker");
j1.href = my_href;
$('#hiddenclicker').trigger('click');
}
然后加载 iframe:
$('#addtownsubmit').click(function() {
var $url='/areastructure/addtown/';
var $get='countryid/'+ ($('#country').val()) + '/regionid/'+ ($('#region').val())+ '/provinceid/'+ ($('#province').val())+ '/originatingcontroller/account/originatingaction/editcontactdetails/'
callBoxFancy($url+$get+'iframe/1');
return false;
});
有没有办法改进此代码,以便我不必包含 html 代码。 jquery 肯定可以为我创建这个隐藏的 div 吗?
I want to dynamically call fancybox to load an iframe. The URL of the iframe will be comprised of some of the elements on the form. I have been using something like this and it works:
<!--***************************************************************-->
<!--this allows fancybox to be called using a dynamic link-->
<div id="hidden_clicker" style="display:none">
<a class="various fancybox.iframe" id="hiddenclicker" href="http://whatever.com" >Hidden Clicker</a>
</div>
<!--***************************************************************-->
then the script :
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'elastic',
closeEffect : 'none'
});
});
function callBoxFancy(my_href) {
var j1 = document.getElementById("hiddenclicker");
j1.href = my_href;
$('#hiddenclicker').trigger('click');
}
then to load the iframe:
$('#addtownsubmit').click(function() {
var $url='/areastructure/addtown/';
var $get='countryid/'+ ($('#country').val()) + '/regionid/'+ ($('#region').val())+ '/provinceid/'+ ($('#province').val())+ '/originatingcontroller/account/originatingaction/editcontactdetails/'
callBoxFancy($url+$get+'iframe/1');
return false;
});
Is there a way to improve this code so that the I don't have to include the html code. Surely jquery could create this hidden div for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要动态创建元素并将它们附加到文档正文中。例如:
You just need to create the elements on the fly and append them to the document body. E.g:
我扩展了卡里姆给我的想法,并做了以下事情:
I extended the idea that karim gave me, and did the following: