使用Ajax实现换肤功能

系统 1499 0
网站换肤是经常要用到的一个功能,但是传统的方式似乎有点瑕疵,本文实现的Ajax换肤有点类似MSNSpace中的用户体验。

 功能:点击linkbutton,在网页中央弹出一个radio单选框,同时背景变成灰色,选择这个单选框的选项,实现换肤功能。

这主要是ModalPopupExtender控件提供的功能,控件设置如下:

< ajaxToolkit:ModalPopupExtender ID ="ModalPopupExtender1" runat ="server" TargetControlID ="LinkButton1" PopupControlID ="Panel1" BackgroundCssClass ="modalBackground" DropShadow ="true" OkControlID ="OkButton" CancelControlID ="CancelButton" OnOkScript ="onOk()" >
</ ajaxToolkit:ModalPopupExtender >

TargetControlID:关联触发按钮; PopupControlID:弹出的单选框,一般使用panel; BackgroundCssClass:弹出单选框后的背景色; DropShadow:弹出单选框后是否需要阴影; OkControlID:关联确定按钮; CancelControlID;关联取消按钮; OnOkScript:关联选择后应该执行的脚本。

其中onOk(),是响应Javascript的代码,使用一个变量来替代css样式。

以下是整个前台代码:

<% ... @PageLanguage = " C# " AutoEventWireup = " true " CodeFile = " changeCSS.aspx.cs " Inherits = " changeCSS " %>

<! DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
< link href ="StyleSheet.css" rel ="stylesheet" type ="text/css" />
< script type ="text/javascript" > ...
var styleToSelect;
function onOk()
... {
document.getElementById(
' Paragraph1 ' ).className = styleToSelect;
}

</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< asp:ScriptManager ID ="ScriptManager1" runat ="server" >
</ asp:ScriptManager >

</ div >
< asp:LinkButton ID ="LinkButton1" runat ="server" Width ="240px" > Pleasechangethestyle </ asp:LinkButton >
< p id =Paragraph1 >
< a href ="http://blog.csdn.net/burningcpu" >< span style ="color:#3366cc" > burningcpu </ span ></ a > ,
IamZhouLu,amemeberofShangHaiIscom.netteam,lovesoftwaredevelopment,enjoyit.
</ p >
< asp:Panel ID ="Panel1" runat ="server" CssClass ="modalPopup" Style ="display:none" Width ="233px" >
< p > Choosethestyleyouwouldlike </ p >
< input id ="RadioA" name ="Radio" onclick ="styleToSelect='sampleStyleA';" type ="radio" />
< label class ="sampleStyleA" for ="RadioA" >
ChooseTHISStyle.
</ label >< br />
< input id ="RadioB" name ="Radio" onclick ="styleToSelect='sampleStyleB';" type ="radio" />
< label class ="sampleStyleB" for ="RadioB" >
ChooseTHISStyle.
</ label >< br />
< input id ="RadioC" name ="Radio" onclick ="styleToSelect='sampleStyleC';" type ="radio" />
< label class ="sampleStyleC" for ="RadioC" >
ChooseTHISStyle.
</ label >< br />
< input id ="RadioD" name ="Radio" onclick ="styleToSelect='sampleStyleD';" type ="radio" />
< label class ="sampleStyleD" for ="RadioD" >
ChooseTHISStyle.
</ label >< br />
< div align ="center" >
< asp:Button ID ="OkButton" runat ="server" Text ="OK" />
< asp:Button ID ="CancelButton" runat ="server" Text ="Cancel" />
</ div >
</ asp:Panel >
&nbsp;
< ajaxToolkit:ModalPopupExtender ID ="ModalPopupExtender1" runat ="server" TargetControlID ="LinkButton1" PopupControlID ="Panel1" BackgroundCssClass ="modalBackground" DropShadow ="true" OkControlID ="OkButton" CancelControlID ="CancelButton" OnOkScript ="onOk()" >
</ ajaxToolkit:ModalPopupExtender >
</ form >
</ body >
</ html >

实现效果:



使用Ajax实现换肤功能


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论