【发布时间】:2011-09-07 01:24:25
【问题描述】:
我有一个链接,单击该链接时使用 .replaceWith 为.swf 文件填充 html 代码的 div。下面是一个例子:
$().ready(function() {
$('a.roots').click(function() {
$('#flashcontent').replaceWith( "<div id=\"flashcontent\">" +
"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"463\" height=\"490\" id=\"FlashID1\" title=\"Liberty Creative Solutions roots\">" +
"<param name=\"movie\" value=\"flash/roots.swf\" />" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"opaque\" />" +
"<param name=\"BGCOLOR\" value=\"#394A59\" />" +
"<param name=\"swfversion\" value=\"6.0.65.0\" />" +
"<param name=\"expressinstall\" value=\"scripts/expressInstall.swf\" />" +
"<object type=\"application/x-shockwave-flash\" data=\"flash/roots.swf\" width=\"463\" height=\"490\">" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"opaque\" />" +
"<param name=\"BGCOLOR\" value=\"#394A59\" />" +
"<param name=\"swfversion\" value=\"6.0.65.0\" />" +
"<param name=\"expressinstall\" value=\"scripts/expressInstall.swf\" />" +
"<div>" +
"<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>" +
"<p>" + "<a href=\"http://www.adobe.com/go/getflashplayer\">" +"<img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" width=\"112\" height=\"33\" />" + "</a>" + "</p>" +
"</div>" +
"</object>" +
"</object>" +
"</div>" );
}); });
我希望在第一次单击链接时插入 swf html。如果再次单击它,我希望将 div html 更改为其他内容。例如:
$('a.roots).click(function() {
$('#flashcontent').replaceWith( "<div id=\"flashcontent\">" +
"<a href=\"#\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Liberty Creative Solutions - Roots','','images/nf_roots_over.jpg',1)\">" + "<img src=\"images/nf_roots.jpg\" name=\"Liberty Creative Solutions - Roots\" width=\"463\" height=\"488\" border=\"0\" id=\"Liberty Creative Solutions - Roots\" />" +"</a>" +
"</div>" );
}); });
如何创建一个侦听器来确定链接是否已被点击一次,然后删除 .swf html 代码并用新代码替换它?
我还想也许可以使用 cookie 来检查:
$('a.roots').click(function() {
if($.cookie('rootsclicked') != null) {
$('#flashcontent').replaceWith( "<a href=\"#\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Liberty Creative Solutions - Roots','','images/nf_roots_over.jpg',1)\">" + "<img src=\"images/nf_roots.jpg\" name=\"Liberty Creative Solutions - Roots\" width=\"463\" height=\"488\" border=\"0\" id=\"Liberty Creative Solutions - Roots\" />" + "</a>" );
}
else {
$('#flashcontent').replaceWith( "<div id=\"flashcontent\">" +
"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"463\" height=\"490\" id=\"FlashID1\" title=\"Liberty Creative Solutions roots\">" +
"<param name=\"movie\" value=\"flash/roots.swf\" />" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"opaque\" />" +
"<param name=\"BGCOLOR\" value=\"#394A59\" />" +
"<param name=\"swfversion\" value=\"6.0.65.0\" />" +
"<param name=\"expressinstall\" value=\"scripts/expressInstall.swf\" />" +
"<object type=\"application/x-shockwave-flash\" data=\"flash/roots.swf\" width=\"463\" height=\"490\">" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"opaque\" />" +
"<param name=\"BGCOLOR\" value=\"#394A59\" />" +
"<param name=\"swfversion\" value=\"6.0.65.0\" />" +
"<param name=\"expressinstall\" value=\"scripts/expressInstall.swf\" />" +
"<div>" +
"<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>" +
"<p>" + "<a href=\"http://www.adobe.com/go/getflashplayer\">" +"<img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" width=\"112\" height=\"33\" />" + "</a>" + "</p>" +
"</div>" +
"</object>" +
"</object>" +
"</div>" );
//and set a cookie named "rootsclicked"
setcookie();
function setCookie(){
document.cookie = 'cookieName=rootsclicked'; expires="1/01/2015 00:00:00";
};
};
});
这样的东西会起作用还是我让它太复杂了?
【问题讨论】:
-
您可以在一些隐藏字段中维护一个计数器,以检查点击次数。
标签: javascript jquery