Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置从JavaScript/JQuery到ASP.NET MVC内联代码的模式窗口的宽度和高度_Jquery_Asp.net Mvc_Lightbox - Fatal编程技术网

设置从JavaScript/JQuery到ASP.NET MVC内联代码的模式窗口的宽度和高度

设置从JavaScript/JQuery到ASP.NET MVC内联代码的模式窗口的宽度和高度,jquery,asp.net-mvc,lightbox,Jquery,Asp.net Mvc,Lightbox,这是视图中的HTML ActionLink帮助程序: <%=Html.ActionLink(Resources.Localize.Routes_WidgetsEdit, "Edit", Model.ContentType.ToString(), new {slug = Model.Slug, modal = true}, new { rel = "shadowbox;height=_HEIGHT_;width=_WIDTH_", title = Resour

这是视图中的HTML ActionLink帮助程序:

<%=Html.ActionLink(Resources.Localize.Routes_WidgetsEdit, "Edit", Model.ContentType.ToString(), 
new {slug = Model.Slug, modal = true}, 
new { 
      rel = "shadowbox;height=_HEIGHT_;width=_WIDTH_", 
      title = Resources.Localize.Routes_WidgetsEdit, 
      @class = "editWidget" 
})%> 

它呈现出这个HTML

<a href="/Tab/Edit/tab-slug/tabgroup-slug?modal=True" rel="shadowbox;height=_HEIGHT_;width=_WIDTH_" title="Edit tab">Edit tab</a>

我想做的是插入高度和宽度的动态值,在JavaScript中,我得到如下结果:

<script type="text/javascript">
var width = $(window).width();
var height = $(window).height();
</script>

变量宽度=$(窗口).width();
var height=$(window.height();
现在我需要一个jQuery选择器或命令来选择页面上连接到Shadowbox的所有链接的“rel”属性(请参见rel中的Shadowbox值)如果它们包含阴影盒和高度和宽度,则在运行时将这两个占位符替换为实际值。解决方案应该是非常防弹的


希望这对所有的jqueryists来说都是小菜一碟

不确定它的防弹性能如何,但像下面这样的东西怎么样:

<html>
<head>

    <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script>
        $(document).ready(function(){
            $("a").each(function()
            {
                if($(this).attr("rel").length > 0)
                {
                    if($(this).attr("rel").indexOf("shadowbox;") >= 0)
                    {
                        $(this).attr("rel", "shadowbox;height=" + $(window).height() + ";width=" + $(window).width());
                    }
                }
            });
        });
    </script>
</head>

<body>

<a href="/Tab/Edit/tab-slug/tabgroup-slug?modal=True" rel="shadowbox;height=_HEIGHT_;width=_WIDTH_" title="Edit tab">Edit tab</a>

<!-- don't set this one -->
<a href="/Tab/Edit/tab-slug/tabgroup-slug?modal=True" title="Edit tab">Edit tab</a>

<a href="/Tab/Edit/tab-slug/tabgroup-slug?modal=True" rel="shadowbox;height=_HEIGHT_;width=_WIDTH_" title="Edit tab">Edit tab</a>

</body>

</html>

$(文档).ready(函数(){
$(“a”)。每个(函数()
{
如果($(this.attr(“rel”).length>0)
{
if($(this.attr(“rel”).indexOf(“shadowbox;”)>=0)
{
$(this).attr(“rel”,“shadowbox;height=“+$(window).height()+”;width=“+$(window).width());
}
}
});
});

完美。我所说的bullletproof是指它不会拾取99%时间内未设置rel=“shadowbox”的其他链接。我认为你的解决方案应该100%有效。