使用jQuery来创建Silverlight

本文介绍了一个jQuery插件,该插件简化了在网页中集成Silverlight控件的过程。通过简单的配置选项,开发者可以轻松地将Silverlight应用程序嵌入到基于jQuery的网页中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jquery插件对象扩展源码:

 

jquery.silverlight.js

jQuery.fn.extend({
    silverlight: function(opts) {
        _opts = jQuery.extend({
            background: 'white',
            minRuntimeVersion: '2.0.31005.0',
            autoUpgrade: true,
            windowless: false,
            width: '100%',
            height: '100%'

        }, opts);

        if (!_opts.source || _opts.source == '') throw new error('「source」属性不能为空 ');

        var obj = $('<object>').attr({
            data: 'data:application/x-silverlight-2,',
            type: 'application/x-silverlight-2',
            width: _opts.width,
            height: _opts.height
        });
        jQuery.each(_opts, function(name, value) {
            if (name == 'width' || name == 'height') return;

            obj.append(
                $('<param>').attr({
                    name: name,
                    value: value
                })
            );
        });
        obj.append(
            $('<a>').attr('href', 'http://go.microsoft.com/fwlink/?LinkID=124807').css('text-decoration', 'none').append(
                $("<img>").attr({
                    src: 'http://go.microsoft.com/fwlink/?LinkId=108181',
                    alt: '立刻安装 Microsoft Silverlight'
                }).css('border-style', 'none')
            )
        );
        $(this).append(obj);
    }
});

使用方法:html文件源码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>jQuery with Silverlight</title>
    <script type="text/javascript" src="jquery-1.3.1.min.js"></script>
    <script type="text/javascript" src="jquery.silverlight.js"></script>   
    <script type="text/javascript">
           $(document).ready(function() {
            $("#silverlightControlHost").silverlight({
                source: 'SilverlightApplication.xap'
            });
        });
    </script>   
    <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
    }
    </style>  
</head>

<body>
    <div id="silverlightControlHost">
    </div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值