使用jquery添加事件单击时无法运行swf时出错?

时间:2012-09-19 08:14:03

标签: jquery

我有一个示例代码:

<a title="click" href="test.swf" class="game-in-link" style="background:#000;width:100%;height:450px;display:block;">CLICK ON PLAY</a>
<div>
<!--
<object width="100%" height="450">
   <param name="movie" value="test.swf"></param>
   <param name="wmode" value="transparent"></param>
   <param name="allowFullScreen" value="true"></param>
   <param name="allowscriptaccess" value="always"></param>
   <embed src="test.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="450"></embed>
</object>
-->
</div>

和jquery:

// Get SWF file
jQuery("a.game-in-link").one('click', function () {
    var anchor = jQuery(this);
    anchor.html(anchor.html().replace('<div><!--', '').replace('--></div>', ''));
    anchor.removeAttr('href');
    return false;
});

=&GT;错误无法filw test.swf,如何获得带有结果的SWF文件?

<object width="100%" height="450">
   <param name="movie" value="test.swf"></param>
   <param name="wmode" value="transparent"></param>
   <param name="allowFullScreen" value="true"></param>
   <param name="allowscriptaccess" value="always"></param>
   <embed src="test.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="450"></embed>
</object>

2 个答案:

答案 0 :(得分:1)

你应该试试这个

<a title="click" href="test.swf" class="game-in-link" style="background:#000;width:100%;height:450px;display:block;">CLICK ON PLAY</a>
<div id="swfPlayer" style="display:none;">
<object width="100%" height="450">
   <param name="movie" value=""></param>
   <param name="wmode" value="transparent"></param>
   <param name="allowFullScreen" value="true"></param>
   <param name="allowscriptaccess" value="always"></param>
   <embed src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="450"></embed>
</object>
</div>

和Jquery

// Get SWF file
jQuery("a.game-in-link").one('click', function () {
    var anchor = jQuery(this);
    var swfPlayer= jQuery('#swfPlayer');
    swfPlayer.find('param[name=movie]').prop("value", anchor.prop("href"));
    swfPlayer.find('embed').prop("src", anchor.prop("href"));
    anchor.removeAttr('href');
    swfPlayer.show();
    return false;
});

答案 1 :(得分:1)

这可行:

jQuery("a.game-in-link").one('click', function (e) {
    e.preventDefault();
    var anchor = jQuery(this).next(); //get next div
    var a = anchor.html().replace('<!--', '').replace('-->', '');
    anchor.html(a).prev().attr('href', '#'); //substitute html and a href
    return false;
});