javascript modle模式的多种方式应用
// jquery-eq.js 一、 var YAHOO = (function($, my){ my.privateAddTopic = function (data) { $('ul > li').live('mousedown', function() { console.log($(this).html() + " down"); }) $('ul > li').live('mouseup', function() { console.log($(this).html() + " up"); }); alert(data); }; my.Name = function (privateName) { return privateName; }; my.privateV = 'private'; return my; })(jQuery, YAHOO || {}); 二、 var YAHOO = (function($, YAHOO){ return { privateAddTopic: function (data) { $('ul > li').live('mousedown', function() { console.log($(this).html() + " down"); }) $('ul > li').live('mouseup', function() { console.log($(this).html() + " up"); }); alert(data); }, Name: function (privateName) { return privateName; }, privateV: 'private' } })(jQuery, YAHOO); 三、 var YAHOO = (function($, YAHOO){ var my = {}, privateName = "博客园"; function privateAddTopic(data) { $('ul > li').live('mousedown', function() { console.log($(this).html() + " down"); }) $('ul > li').live('mouseup', function() { console.log($(this).html() + " up"); }); $('ul > li').live('click', function() { var ts = $(this); var index = ts.index(); var html = ts.html(); if (0 == index) { ts.addClass('ts') } else if (1 == index) { ts.addClass('ts') } else if (2 == index) { ts.addClass('ts') } else if (3 == index) { ts.addClass('ts') } }); $('ul > li').live('mouseout', function() { var ts = $(this); var index = ts.index(); var html = ts.html(); if (0 == index) { ts.removeClass('ts') } else if (1 == index) { ts.removeClass('ts') } else if (2 == index) { ts.removeClass('ts') } else if (3 == index) { ts.removeClass('ts') } }); } my.Name = privateName; my.AddTopic = function (data) { privateAddTopic(data); }; return my; })(jQuery, YAHOO);
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'jquery-eq.jsp' starting page</title> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <style type="text/css"> ul > li { background-color: #FCFEFC; border: 1px solid #F5F5F5; float: left; list-style: none outside none; margin: 10px; padding: 5px; } ul > li:hover { border: 1px solid gray; border-radius: 5px; } .ts { -moz-transform: rotate(45deg); -webkit-transform: rotate(45deg); -o-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } </style> <script type="text/javascript" src="js/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="js/jquery-eq.js"></script> <script type="text/javascript"> YAHOO.privateAddTopic(YAHOO.Name('private verial')); alert(YAHOO.privateV); </script> </head> <body> <ul> <li>basketball</li> <li>football</li> <li>one</li> <li>two</li> </ul> <div id="eee"></div> </body> </html>
相关推荐
nmgxzm00 2020-11-10
ifconfig 2020-10-14
hhanbj 2020-11-17
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
81427005 2020-11-11
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23
淼寒儿 2020-10-22