在Asp.net中使用JQuery插件之jTip
生活随笔
收集整理的这篇文章主要介绍了
在Asp.net中使用JQuery插件之jTip
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
jTip 是个轻量级的提示插件。默认支持两个参数:
- width宽度,default value :250px
- link 要link的URL
对应的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: }
然后我们看到初始化时,是选择所有class=jTip的<a>标签,然后给它们加上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: }
接着取得当前id的位置计算将要显示DIV的位置,code也不复杂:
其它的一些help function可以参看source code,你可以从这里下载它.
如何使用呢?我们引入它与相应的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.这个用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中这么写:
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>
默认是取name attribute value为Caption,上面是三种典型的link。id是我们自己传给Handler的QueryString,最终效果如下图所示:
希望这篇POST对您有帮助。
Author Petter Liu http://wintersun.cnblogs.com
总结
以上是生活随笔为你收集整理的在Asp.net中使用JQuery插件之jTip的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: XML CDATA
- 下一篇: 使用临界区 CRITICAL_SECTI