在Asp.net中使用JQuery插件之jTip
生活随笔
收集整理的這篇文章主要介紹了
在Asp.net中使用JQuery插件之jTip
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
???? jTip 是個(gè)輕量級(jí)的提示插件。默認(rèn)支持兩個(gè)參數(shù):
- width寬度,default value :250px
- ????? link 要link的URL
對(duì)應(yīng)的Source code是:
1: var params = parseQuery( queryString ); 2: if(params['width'] === undefined){params['width'] = 250}; 3: if(params['link'] !== undefined){ 4: $('#' + linkId).bind('click',function(){window.location = params['link']}); 5: $('#' + linkId).css('cursor','pointer'); 6: }
然后我們看到初始化時(shí),是選擇所有class=jTip的<a>標(biāo)簽,然后給它們加上hover方法,讓click方法失效
1: //on page load (as soon as its ready) call JT_init 2: $(document).ready(JT_init); 3: ? 4: function JT_init(){ 5: $("a.jTip") 6: .hover(function(){JT_show(this.href,this.id,this.name)},function(){$('#JT').remove()}) 7: .click(function(){return false}); 8: }
接著取得當(dāng)前id的位置計(jì)算將要顯示DIV的位置,code也不復(fù)雜:
?
其它的一些help function可以參看source code,你可以從這里下載它.
如何使用呢?我們引入它與相應(yīng)的CSS:
1: <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min.js"></script> 2: <script src="js/jtip.js" type="text/javascript"></script>
在asp.net webform中使用Handler,asp.net mvc 可以用action.這個(gè)用Handler演示:
1: [WebService(Namespace = "http://tempuri.org/")] 2: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 3: public class DataHandler : IHttpHandler 4: { 5: #region Properties (1) 6: ? 7: public bool IsReusable 8: { 9: get 10: { 11: return false; 12: } 13: } 14: ? 15: #endregion Properties 16: ? 17: #region Methods (2) 18: ? 19: // Public Methods (1) 20: ? 21: public void ProcessRequest(HttpContext context) 22: { 23: context.Response.ContentType = "text/plain"; 24: context.Response.Write(GetData(Convert.ToInt32(context.Request.QueryString["id"]))); 25: } 26: // Private Methods (1) 27: ? 28: private string GetData(int key) 29: { 30: Dictionary<int, string> mydatadic = new Dictionary<int, string>(); 31: mydatadic.Add(0, "Nothing in life is to be feared. It is only to be understood,this is id equal 0"); 32: mydatadic.Add(1, "<strong>A man</strong> is not old as long as he is seeking something. A man is not old until regrets take the place of dreams. ,this is id equal 1"); 33: mydatadic.Add(2, "A man can succeed at almost anything for which he has unlimited enthusiasm.,this is id equal 2"); 34: mydatadic.Add(3, "To live is to function. That is all there is in living. ,this is id equal 3"); 35: return mydatadic[key]; 36: } 37: ? 38: #endregion Methods 39: }?
好的,在最終的HTML中這么寫(xiě):
1: <span class="formInfo"><a href="DataHandler.ashx?id=0&width=375" class="jTip" id="one" name="Password must follow these rules:">?</a></span> 2: <br> 3: ? 4: <p><a href="DataHandler.ashx?id=3&width=175&link=http://www.google.com" name="Before You Click..." id="googleCopy" class="jTip">Go To Google</a></p> 5: ? 6: <a href="DataHandler.ashx?id=3" class="jTip" id="three">Tip No Caption</a>
默認(rèn)是取name attribute value為Caption,上面是三種典型的link。id是我們自己傳給Handler的QueryString,最終效果如下圖所示:
希望這篇POST對(duì)您有幫助。
Author? Petter Liu? http://wintersun.cnblogs.com
總結(jié)
以上是生活随笔為你收集整理的在Asp.net中使用JQuery插件之jTip的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: XML CDATA
- 下一篇: 如何使用Android SDK开发And