jQuery日历插件FullCalendar使用方法
作者:admin 日期:2021-04-23
html代码片段
- <head>
- <meta charset='utf-8' />
- <link href='../fullcalendar.css' rel='stylesheet' />
- <link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
- <script src='../lib/moment.min.js'></script>
- <script src='../lib/jquery.min.js'></script>
- <script src='../fullcalendar.min.js'></script>
- </head>
- <div id="calendar"></div>
js代码片段
- function initdata(){
- var calendar = $('#calendar').fullCalendar({
- /**
- * 默认显示的视图
- * month 一页显示一月, 日历样式
- basicWeek 一页显示一周, 无特殊样式
- basicDay 一页显示一天, 无特殊样式
- agendaWeek 一页显示一周, 显示详细的24小时表格
- agendaDay 一页显示一天, 显示详细的24小时表格
- listYear 年列表(V3.*支持)
- listMonth 月列表(V3.*支持)
- listWeek 周列表(V3.*支持)
- listDay 日列表(V3.*支持)
- */
- defaultView:"agendaWeek", //进入组件默认渲染的视图,默认为month
- customButtons: {//自定义header属性中按钮[customButtons与header并用]
- myCustomButton: {
- text: 'custom!',
- click: function() {
- }
- }
- },
- header: {
- left: 'prev,next today', //上一页、下一页、今天
- center: 'title myCustomButton', //居中:时间范围区间标题
- right: 'month,agendaWeek,agendaDay,listWeek'//右边:显示哪些视图
- },
- height : 600,//组件高度,默认aspectRatio即纵横比;parent父容器大小;auto自动不带滚动条;
- contentHeight : 200,//组件中的内容高度,默认aspectRatio即纵横比;auto自动不带滚动条;支持数字和函数返回像素;
- // aspectRatio : 2, //宽度:高度 比例,默认1.35,可自定义
- handleWindowResize : false, //组件随浏览器高宽变化自适应,默认true支持自适应
- // windowResizeDelay : 200,//窗体自适应延迟多少毫秒
- firstDay : 1, //视图从每周几开始,默认0为周日,1为周1,
- isRTL : false,//从右到左显示模式,默认false
- // weekends : false,//是否在视图中显示周六、周日,默认true
- // hiddenDays: [ 1,5 ],//隐藏星期1、星期5
- fixedWeekCount : false, //月视图下,显示6周(不够的显示下个月的)true;默认true
- weekNumbers : true, //是否在视图左边显示这是第多少周,默认false
- // businessHours : {}//设置哪些时间段重点标记颜色
- eventLimit: true,//数据条数太多时,限制各自里显示的数据条数(多余的以“+2more”格式显示),默认false不限制,支持输入数字设定固定的显示条数
- // eventLimitClick : "day",//接eventLimit属性,多余的内容点击事件,默认有一套弹窗格式,支持跳转到不同视图、也支持自定义function,详情见官方文档
- viewRender : function(view,element){//在视图被渲染时触发(切换视图也触发) 参数view为视图对象,参数element为Jquery的视图Dom
- },
- // viewDestroy : function(view, element){}, //类似viewRender,在视图被销毁时触发
- windowResize : function(){//浏览器窗体变化时触发
- },
- // allDaySlot : false, //视图在周视图、日视图顶部显示“全天”信息,默认true显示全天
- allDayText : "全天", //自定义全天视图的名称
- slotDuration : "01:00:00", //一格时间槽代表多长时间,默认00:30:00(30分钟)
- slotLabelFormat : "H(:mm)a",//日期视图左边那一列显示的每一格日期时间格式
- slotLabelInterval : "02:00:00", //日期视图左边那一列多长间隔显示一条日期文字(默认跟着slotDuration走的,可自定义)
- snapDuration : "05:00:00",//其实就是动态创建一个日程时,默认创建多长的时间块
- // scrollTime : "06:00:00",//多远开始往下滚动,默认6小时
- // minTime : "02:00:00",//周/日视图左边时间线显示的最小日期,默认00:00:00
- // maxTime : "08:00:00",//周/日视图左边时间线显示的最大日期,默认24:00:00
- slotEventOverlap : false,//相同时间段的多个日程视觉上是否允许重叠,默认true允许
- // listDayFormat : false,//listview视图下,每天的分割区,[左边]的标题自定义,false表示无标题
- // listDayAltFormat : false,//listview视图下,每天的分割区,[右边]的标题自定义,false表示无标题
- noEventsMessage : "L没数据啊", //listview视图下,无数据时显示提示
- defaultDate : '2016-10-13',//默认显示那一天的日期视图
- nowIndicator : true, //周/日视图中显示今天当前时间点(以红线标记),默认false不显示
- // locale : "zh-cn", //国际化,前提引用fileinput_locale_zh.js
- // timeFormat : "h:mm", //全局的日期显示格式(自定义成如12:00或12am等)
- // columnFormat : "", //顶部日期显示格式
- // titleFormat : "",//顶部title区域格式化
- buttonText : {today:'今天',month:'月',week:'周',day:'日',listWeek:'列表'}, //对应顶部操作按钮的名称自定义
- monthNames : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], //月份自定义命名
- monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], //月份缩略命名(英语比较实用:全称January可设置缩略为Jan)
- dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
- dayNamesShort: ["周日", "周一", "周二", "周三", "周四", 周五, "六"],
- weekNumberTitle : "周",//周的国际化,默认为"W"
- // displayEventTime : false,//每一个日程块中是否显示时间,默认true显示
- // displayEventEnd : true,//是否显示日程块中的“结束时间”,默认true,如果false则只显示开始时间
- eventLimitText : "更多", //当一块区域内容太多以"+2 more"格式显示时,这个more的名称自定义(应该与eventLimit: true一并用)
- dayPopoverFormat : "YYYY年M月D日", //点开"+2 more"弹出的小窗口标题,与eventLimitClick可以结合用
- navLinks : true,// “xx周”是否可以被点击,默认false,如果为true则周视图“周几”被点击之后进入日视图。本地测试:没什么效果
- // navLinkDayClick: function(date, jsEvent) { //依赖navLinks : true , 点击顶部“日”时触发
- // return true;
- // },
- // navLinkWeekClick: function(weekStart, jsEvent) { //依赖navLinks : true , 点击顶部“周”时触发
- },
- dayClick: function(date, jsEvent, view) {//空白的日期区,单击时触发
- },
- eventClick: function(calEvent, jsEvent, view) {//日程区块,单击时触
- return false; //return false可以阻止点击后续事件发生(比如event中的url跳转事件)
- },
- eventMouseover: function(calEvent, jsEvent, view){//鼠标在日程区块上时触发
- $(this).css('background-color', 'gray');
- },
- eventMouseout: function(calEvent, jsEvent, view){//鼠标从日程区块离开时触发
- $(this).css('background-color', 'yellow');
- },
- selectable: true,//允许用户可以长按鼠标选择多个区域(比如月视图,可以选中多天;日视图可以选中多个小时),默认false不能选择多区域的
- selectHelper: true,//接selectable,周/日视图在选择时是否预先画出“日程区块”的样式出来
- unselectAuto : true,//是否点击页面上的其他地方会导致当前的选择被清除,默认true
- unselectCancel : "",//一种方法来指定元素,会忽略unselectauto选项,默认''
- selectOverlap : true,//确定用户是否被允许选择被事件占用的时间段,默认true可占用时间段
- // selectConstraint : ,//限制用户选择指定时间段的日程数据:an event ID, "businessHours", object
- selectAllow : function(selectInfo){ //精确的编程控制用户可以选择的地方,返回true则表示可选择,false表示不可选择
- return true;
- },
- select: function(start, end,jsEvent,view) { //点击空白区域/选择区域内容触发
- },
- unselect : function(view, jsEvent){//选择操作取消时触发
- },
- /**Event Object配置start */
- // allDayDefault : null,//是否默认将日程全部显示在“全天”里面(boolean or null),默认为undefined,即根据event时间值智能判断,这个属性太强悍,不敢用
- // startParam:"start",//Event Object中定义[开始时间]的变量,默认是start,可自定义变量名以防冲突
- // endParam:"end", //Event Object中定义[结束时间]的变量,默认是end,可自定义变量名以防冲突
- // timezoneParam : "timezone", //Event Object中定义[时区]的变量,默认是本地时区,可自定义变量名以防冲突,可更改时区如( "America/Chicago" or "UTC")
- lazyFetching : true, //是否启用懒加载技术--即只取当前条件下的视图数据,其它数据在切换时触发,默认true只取当前视图的,false是取全视图的
- defaultTimedEventDuration : "02:00:00", //在Event Object中如果没有end参数时使用,如start=7:00pm,则该日程对象时间范围就是7:00~9:00
- defaultAllDayEventDuration : { days: 1 }, //默认1天是多长,(有的是采用工作时间模式,所以支持自定义)
- // forceEventDuration : false, //诉老夫无能为力,愣是没搞懂什么意思,默认false
- // eventDataTransform : function(eventData){return [events...]}, //当从第三方取数不规则时(如下面的JSON或google),可通过此钩子函数进行数据整理,转换为fullcalendar识别的event object
- loading : function(isLoading, view){ //视图数据加载中、加载完成触发
- if(isLoading == true){
- console.log("view:"+view+",开始加载");
- }else if(isLoading == false){
- console.log("view:"+view+",加载完成");
- }else{
- console.log("view:"+view+",除非天塌下来否则不会进这个分支");
- }
- },
- // nextDayThreshold : "09:00:00", //当一个事件的结束时间跨越到另一天,最短的时间,它必须为它的渲染,如果它在这一天。
- eventOrder : "title", //多个相同的日程数据排序方式,String / Array / Function, 默认值: "title"
- eventRender : function(event, element, view) {//当Event对象开始渲染时触发
- },
- // eventAfterRender : function( event, element, view ) { } //当Event对象结束渲染时触发
- eventAfterAllRender : function(view){
- }, //当所有Event对象渲染完成时触发
- // eventDestroy : function( event, element, view ) { }//一个Event DOM销毁时触发
- /**Event Object配置end */
- /**Event Rendering配置(一些样式等配置) start*/
- // eventColor: '#378006', //不解释,所有的日程区块生效,如要对指定数据源生成参见EventSource,如要对指定Event生效,参见EventObject
- // eventBackgroundColor:"", //同上,不解释
- // eventBorderColor:"", //同上,不解释
- // eventTextColor:"" //同上,不解释
- /**Event Rendering配置 end*/
- editable: true,//支持Event日程拖动修改,默认false
- eventStartEditable : true, //Event日程开始时间可以改变,默认true,如果是false其实就是指日程块不能随意拖动,只能上下拉伸改变他的endTime
- eventDurationEditable : false, //Event日程的开始结束时间距离是否可以改变,默认true,如果是false则表示开始结束时间范围不能拉伸,只能拖拽
- // dragRevertDuration : 500, //拖拽取消恢复花费时间,单位毫秒,这个就用默认的差不多了
- dragOpacity:0.2,//拖拽时不透明度,0.0~1.0之间,数字越小越透明
- dragScroll : true,//是否在拖拽时自动移动容器,默认true
- eventOverlap : true, //拖拽时是否重叠
- eventConstraint : {//限制拖拽拖放的位置(即限制有些地方拖不进去):an event ID, "businessHours", object
- start: '10:00', // a start time (10am in this example)
- end: '18:00', // an end time (6pm in this example)
- dow: [ 1, 2, 3, 4 ] // days of week. an array of zero-based day of week integers (0=Sunday) (Monday-Thursday in this example)
- },
- longPressDelay : 1000, //面向可touch设备(如移动设备),长按多少毫秒即可拖动,默认1000毫秒(1S)
- eventDragStart : function(event, jsEvent, ui, view){//日程开始拖拽时触发
- },
- eventDragStop : function(event, jsEvent, ui, view){//日程拖拽停止
- },
- eventDrop : function(event, delta, revertFunc, jsEvent, ui, view){ //日程拖拽停止并且已经拖拽到其它位置了
- },
- eventResizeStart : function( event, jsEvent, ui, view ) { //日程大小调整开始时触发
- },
- eventResizeStop : function(event, jsEvent, ui, view){ //日程大小调整停止时触发
- },
- eventResize : function(event, delta, revertFunc, jsEvent, ui, view){ //日程大小调整完成并已经执行更新时触发
- },
- /* 访问后台URL,动态返回JSON数据的形式,这种是直接集成了jQuery.ajax,其实并不灵活
- events: {
- url: '/myfeed.php',
- type: 'POST',
- data: {
- custom_param1: 'something',
- custom_param2: 'somethingelse'
- },
- error: function() {
- alert('there was an error while fetching events!');
- },
- color: 'yellow', // a non-ajax option
- textColor: 'black' // a non-ajax option
- },
- */
- /* 第二种:基于function的数据获取,通常是在切换上一页、下一页、视图切换时触发,非常适合动态数据获取
- events: function(start, end, timezone, callback) {
- $.ajax({
- url: 'myxmlfeed.php',
- dataType: 'xml',
- data: {
- // our hypothetical feed requires UNIX timestamps
- start: start.unix(),
- end: end.unix()
- },
- success: function(doc) {
- var events = [];
- $(doc).find('event').each(function() {
- events.push({
- title: $(this).attr('title'),
- start: $(this).attr('start') // will be parsed
- });
- });
- callback(events);
- }
- });
- },
- */
- events: [//第三种:直接是数组的形式传入
- {
- title: 'All Day Event',
- start: '2016-10-13'
- },
- {
- title: 'Long Event',
- start: '2016-10-07',
- end: '2016-10-10'
- },
- {
- id: 991,
- title: 'Repeating Event',
- start: '2016-10-09T16:00:00'
- },
- {
- id: 999,
- title: 'Repeating Event',
- start: '2016-10-16T16:00:00'
- },
- {
- title: 'Conference',
- start: '2016-10-11',
- end: '2016-10-13'
- },
- {
- title: 'Meeting',
- start: '2016-10-12T10:30:00',
- end: '2016-10-12T12:30:00'
- },
- {
- title: 'Lunch',
- start: '2016-10-12T12:00:00'
- },
- {
- title: 'Meeting',
- start: '2016-10-12T14:30:00'
- },
- {
- title: 'Happy Hour',
- start: '2016-10-12T17:30:00'
- },
- {
- title: 'Dinner',
- start: '2016-10-12T20:00:00'
- },
- {
- title: 'Birthday Party',
- start: '2016-10-13T07:00:00'
- },
- {
- title: 'Click for Google',
- url: 'http://google.com/',
- start: '2016-10-28'
- }
- ]
- /* 多数据源支持:场景可能是从多种模块取数据,比如从会议取会议日程、从计划取计划日程,而且要求会议、计划日程颜色显示不一样,那么就可以用这种
- eventSources: [
- {
- events: function(start, end, timezone, callback){...},
- color: 'black', // an option!
- textColor: 'yellow' // an option!
- },
- {
- googleCalendarId: 'abcd1234@group.calendar.google.com',
- color: 'yellow', // an option!
- textColor: 'black' // an option!
- }
- ]
- */
- });
- // 日期格式需要遵守fullCalendar引用的moment.js规则:https://fullcalendar.io/docs/utilities/Moment/
- // Event Object 就是一个日程区块,数据元,通常以数组的形式传入option->events中 见 https://fullcalendar.io/docs/event_data/Event_Object/
- // Event Source Object 不好理解,大概就是一组日程数据源对象吧,可以是一个events、也可以是JSON、还可以是Google Calendar的数据 见 https://fullcalendar.io/docs/event_data/Event_Source_Object/
- /* updateEvent更新一个日程对象
- $('#calendar').fullCalendar({
- eventClick: function(event, element) {
- event.title = "CLICKED!";
- //更新日程对象信息
- $('#calendar').fullCalendar('updateEvent', event);
- }
- });
- */
- // .fullCalendar( 'clientEvents' [, idOrFilter ] ) -> Array 从内存中筛选指定的event,[, idOrFilter ]==>省略号删除全部、ID数组删除有ID的日程、也可传入Event对象,建议使用时详细查看官方文档
- // .fullCalendar( 'removeEvents' [, idOrFilter ] ) 删除日程,[, idOrFilter ]参见clientEvents,建议使用时详细查看官方文档
- // .fullCalendar( 'refetchEvents' ) 刷新所有数据源的日历视图,建议使用时详细查看官方文档
- // .fullCalendar( 'refetchEventSources', sources ) 刷新指定数据源的日历视图(与eventSource有关配合用),建议使用时详细查看官方文档
- // .fullCalendar( 'addEventSource', source ) 动态添加一个数据源(与eventSource有关配合用),建议使用时详细查看官方文档
- // .fullCalendar( 'removeEventSource', source ) 动态删除一组数据源(与eventSource有关配合用),建议使用时详细查看官方文档
- // .fullCalendar( 'removeEventSources', optionalSourcesArray ) 动态删除多个数据源,如果optionalSourcesArray未指定则删除全部,建议使用时详细查看官方文档
- // .fullCalendar( 'getEventSources' ) 返回所有的数据源
- // .fullCalendar( 'getEventSourceById', id ) 根据ID获取数据源
- // $('#calendar').fullCalendar('render'); 渲染日历视图
- // $('#calendar').fullCalendar('destory'); 销毁日历视图
- // var view = $('#calendar').fullCalendar('getView'); //获取当前视图对象
- // console.log("name:"+view.name+"|title:"+view.title+"|start:"+view.start+"|end:"+view.end+"|intervalStart:"+view.intervalStart+"|intervalEnd:"+view.intervalEnd);
- // $('#calendar').fullCalendar('changeView', "month" ); //切换为其它视图
- // $('#calendar').fullCalendar('prev'); //切换到当前视图的上一页(类似于顶部的“<”箭头)
- // $('#calendar').fullCalendar('next'); //切换到当前视图的下一页(类似于顶部的“>”箭头)
- // $('#calendar').fullCalendar('prevYear') //切换到上一年
- // $('#calendar').fullCalendar('nextYear') //切换到下一年
- // $('#calendar').fullCalendar('today'); //日期视图跳转到“今天”
- // $('#calendar').fullCalendar( 'gotoDate', date ); //日期视图跳转到指定时间
- // $('#calendar').fullCalendar( 'incrementDate', duration ); //日期视图向前或向后移动固定的时间,duration可以为={ days:1, hours:23, minutes:59 }
- // var moment = $('#calendar').fullCalendar('getDate'); //获取当前视图的日期对象,(如果月视图则返回月初到月末,周视图返回周初到周末)
- // console.log("The current date of the calendar is " + moment.format());
- // $('#calendar').fullCalendar( 'select', start, [ end ], [ resource ] ); //js动态选择某个时间段的日程
- // .fullCalendar( 'unselect' ); //js动态取消选择的日程
- // var locale = $('#calendar').fullCalendar('option', 'locale'); //option支持get,注:不仅限于locale,还包括其它option操作
- // $('#calendar').fullCalendar('option', {locale: 'fr',isRTL: true}); //option支持set,注:不仅限于locale,还包括其它option操作
- // var calendar = $('#calendar').fullCalendar('getCalendar'); //支持动态绑定/解绑fullcalendar中的事件
- // calendar.on('dayClick', function(date, jsEvent, view) {console.log('clicked on ' + date.format());});
- // .fullCalendar( 'renderEvent', event [, stick ] ); //渲染一个新的Event,建Demo select方法
- // .fullCalendar( 'rerenderEvents' ) //渲染那所有的Event
- });
- }
jQuery跳转到另一个页面
作者:admin 日期:2021-01-05
1.我们可以利用http的重定向来跳转
返回顶部的jquery插件
作者:admin 日期:2020-02-16
Easy Peasy
Download the minified version of the plugin, include it after jQuery and:
<script> jQuery(document).ready(function(){ jQuery.goup(); }); </script> 带参数的:点击下载此文件 <script type="text/javascript"> $(document).ready(function () { $.goup({ trigger: 100, bottomOffset: 50, locationOffset: 70,containerColor: '#990000', title: '返回顶部', titleAsText: false }); }); </script>
Demo
Yeah! You can see it in action on this page. If you scroll down, you can see, on the bottom right, the magic!
Options
Name | Description | Type | Default |
---|---|---|---|
location |
On which side the button will be shown ("left" or "right") | String | right |
locationOffset |
How many pixel the button is distant from the edge of the screen, based on the location setted | Integer | 20 |
bottomOffset |
How many pixel the button is distant from the bottom edge of the screen | Integer | 10 |
containerRadius |
Let you transform a square in a circle (yeah, it's magic!) | Integer | 10 |
containerClass |
The class name given to the button container | String | goup-container |
arrowClass |
The class name given to the arrow container | String | goup-arrow |
containerColor |
The color of the container (in hex format) | String | #000 |
arrowColor |
The color of the arrow (in hex format) | String | #fff |
trigger |
After hoiw many scrolled down pixels the button must be shown (bypoassed by alwaysVisible ) |
Integer | 500 |
entryAnimation |
The animation of the show and hide events of the button ("slide" or "fade") | String | fade |
alwaysVisible |
Set to true if u want the button to be always visible (bypass trigger ) |
Boolean | false |
goupSpeed |
The speed at which the user will be brought back to the top ("slow", "normal" or "fast") | String | slow |
hideUnderWidth |
The threshold of window width under which the button is permanently hidden | Integer | 500 |
title |
A text to show on the button mouse hover | String | '' |
titleAsText |
If true the hover title becomes a true text under the button | Boolean | false |
titleAsTextClass |
The class name given to the title text | String | goup-text |
zIndex |
Set the z-index | Integer | 1 |
JS/JQuery获取当前元素的上一个/下一个兄弟级元素等元素的方法
作者:admin 日期:2019-10-06
- $(function(){
- //遍历获取的input元素对象数组,绑定click事件
- var len = $("input[type='file']").length;
- for(var i = 0; i < len; i++){
- $("input[type='file']").eq(i).click(function(){
- $(this).next().val("");
- $(this).next().hide();
- $(this).css("width","200px");
- })
- }
- }
jQuery获取:
jQuery.parent(expr),找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(".class")
jQuery.parents(expr),类似于jQuery.parents(expr),但是是查找所有祖先元素,不限于父元素
jQuery.children(expr),返回所有子节点,这个方法只会返回直接的孩子节点,不会返回所有的子孙节点
jQuery.contents(),返回下面的所有内容,包括节点和文本。这个方法和children()的区别就在于,包括空白文本,也会被作为一个jQuery对象返回,children()则只会返回节点
jQuery.prev(),返回上一个兄弟节点,不是所有的兄弟节点
jQuery.prevAll(),返回所有之前的兄弟节点
jQuery.next(),返回下一个兄弟节点,不是所有的兄弟节点
jQuery.nextAll(),返回所有之后的兄弟节点
jQuery.siblings(),返回兄弟姐妹节点,不分前后
jQuery.find(expr),跟jQuery.filter(expr)完全不一样:
jQuery.filter(),是从初始的jQuery对象集合中筛选出一部分,而
jQuery.find(),的返回结果,不会有初始集合中的内容,比如$("p").find("span"),是从<p>元素开始找<span>,等同于$("p span")
JS获取:
- var chils= s.childNodes; //得到s的全部子节点
- var par=s.parentNode; //得到s的父节点
- var ns=s.nextSibling; //获得s的下一个兄弟节点
- var ps=s.previousSibling; //得到s的上一个兄弟节点
- var fc=s.firstChild; //获得s的第一个子节点
- var lc=s.lastChild; //获得s的最后一个子节点
JS获取节点父级,子级元素:JS的方法会比JQUERY麻烦很多,主要则是因为FF、谷歌浏览器会把你的换行也当作DOM元素:空的text元素,目前IE也是这样
- <div id="test">
- <div></div>
- <div></div>
- </div>
bootstrap怎么设置下拉菜单不点击,改成鼠标悬停直接显示下拉菜单
作者:admin 日期:2017-05-22
方法一:
实际上比较简单,只需要加一个css设置下hover的状态,把下拉菜单设置成block,具体css:
- .nav
- > li:hover .dropdown-menu {display: block;}
但是主导航失去链接的效果!
方法二:
不仅可以解决Bootstrap鼠标悬停的问题,还可以让一个菜单恢复链接实现点击
下拉菜单效果是JS实现的,分析bootstrap.js文件发现,Bootstrap把下拉菜单写成了一个JQuery插件,在dropdown代码段中找到了关键的几句:
$(document)
.on('click.bs.dropdown.data-api', clearMenus)
.on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.bs.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
把其中的click.bs.dropdown.data-api事件关闭就好,代码如下:
- $(document).ready(function(){
- $(document).off('click.bs.dropdown.data-api');
- });
这样可以让一级菜单恢复href属性,起到超链接功能。
至于下拉菜单悬浮,鼠标放上就显示,按照楼上的方法就好。或者用js来实现:
- $(document).ready(function(){
- dropdownOpen();//调用
- });
/**
* 鼠标划过就展开子菜单,免得需要点击才能展开
*/
- function dropdownOpen() {
- var $dropdownLi = $('li.dropdown');
- $dropdownLi.mouseover(function() {
- $(this).addClass('open');
- }).mouseout(function() {
- $(this).removeClass('open');
- });
- }
使用JQuery使Div居中
作者:admin 日期:2015-05-29
Div居中是一个比较常见的需求。下面介绍一种使用JQuery使Div居中的方法
先假设有这样一个Div,<div id="d">test</div>
首先是要把需要居中的Div进行绝对定位,如:
<style type="text/css">
#d {
position: absolute;
width: 500;
height: 300;
border: 1px solid red;
}
</style>
有了这样的样式定义之后就是使其居中的js代码了。
- var obj = $("#d");//获得相应的Div对象
- var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离
- var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离
- obj.css("top",y).css("left",x);
上面这段代码可以在页面一加载完就执行。
改进后的代码:
- $(document).ready(function(){
- middle();
- });
- $(window).resize(function(){
- middle();
- });
- function middle(){
- var obj = $("#mainbg");//获得相应的Div对象
- var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离
- var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离
- obj.css("top",y).css("left",x);
- }
上面的代码实现窗口大小变化后始终居中。
jQuery禁止鼠标右键
作者:admin 日期:2015-05-29
jQuery屏蔽鼠标右键:
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
--------------------------------------------------------------------------------------------------
JS屏蔽鼠标右键:
<script language="JavaScript">
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</script>
--------------------------------------------------------------------------------------------------
jquery禁止右键弹出的突破方法:
如: $(document).bind("contextmenu", function() { return false; }); //这段JS代码将禁止右键弹出
突破方法:
地址栏中输入:javascript:alert($(document).unbind("contextmenu",""));
jquery禁用右键、文本选择功能、复制按键的实现
作者:admin 日期:2013-05-26
同时适合IE、firefox、谷歌浏览器下适用,经过筛选代码如下:
- //禁用右键、文本选择功能、复制按键
- $(document).bind(“contextmenu”,function(){return false;});
- $(document).bind(“selectstart”,function(){return false;});
- $(document).keydown(function(){return key(arguments[0])});
- //按键时提示警告
- function key(e){
- var keynum;
- if(window.event){
- keynum = e.keyCode; // IE
- }else if(e.which){
- keynum = e.which; // Netscape/Firefox/Opera
- }
- if(keynum == 17){
- alert(“禁止复制内容!”);
- return false;
- }
- }
- //禁用右键、文本选择功能、复制按键
- $(document).bind("contextmenu",function(){return false;});
- $(document).bind("selectstart",function(){return false;});
- $(document).keydown(function(){return key(arguments[0])});
- //按键时提示警告
- function key(e){
- var keynum;
- if(window.event) // IE
- {
- keynum = e.keyCode;
- }
- else if(e.which) // Netscape/Firefox/Opera
- {
- keynum = e.which;
- }
- if(keynum == 17){ alert("禁止复制内容!");return false;}
- }
- //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键
- function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键
- function window.onhelp(){return false} //屏蔽F1帮助
- function document.onkeydown(){
- if((window.event.altKey)&&
- ((window.event.keyCode==37)|| //屏蔽Alt+方向键←
- (window.event.keyCode==39))){ //屏蔽Alt+方向键→
- alert("不准你使用ALT+方向键前进或后退网页!");
- event.returnValue=false;
- } if((event.keyCode==8)|| //屏蔽退格删除键
- (event.keyCode==116)|| //屏蔽F5刷新键
- (event.ctrlKey && event.keyCode==82)){ //Ctrl+R
- event.keyCode=0;
- event.returnValue=false;
- }
- if(event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11
- if(event.ctrlKey && event.keyCode==78)event.returnValue=false; //屏蔽Ctrl+n
- if(event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽shift+F10
- if(window.event.srcElement.tagName=="A" && window.event.shiftKey)
- window.event.returnValue=false; //屏蔽shift加鼠标左键新开一网页
- if((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4
- window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
- return false;
- }
- }
Jquery实现链接批量设置新窗口打开
作者:admin 日期:2012-04-30
首先调用jquery类文件:
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
非站内链接新窗口打开:
- <script type="text/javascript">
- jQuery(function($){
- $("a[href*='://']:not(a[href^='http://www.jlist.cn'],a[href^='javascript:'])").attr("target", "_blank");})
- </script>
实际上是jquery方法属性的基本应用!
演示地址:https://blog.guanjianci.net/codetest/jquery/openwithblank.html
jquery页面中固定显示div层
作者:admin 日期:2012-04-27
这个是别人写的代码,自己实际用的时候对代码做了改动,主要需要新增一些功能!
- /*任意位置浮动固定层*/
- /*没剑(http://regedit.cnblogs.com) 2009-03-04*/
- /*说明:可以让指定的层浮动到网页上的任何位置,当滚动条滚动时它会保持在当前位置不变,不会产生闪动*/
- /*2009-06-10修改:重新修改插件实现固定浮动层的方式,使用一个大固定层来定位
- /*2009-07-16修改:修正IE6下无法固定在top上的问题
- /*09-11-5修改:当自定义层的绝对位置时,加上top为空值时的判断
- 这次的方法偷自天涯新版页
- 经多次测试,基本上没bug~
- 有问题的朋友欢迎到偶的博客http://regedit.cnblogs.com上提出
- */
- /*调用:
- 1 无参数调用:默认浮动在右下角
- $("#id").floatdiv();
- 2 内置固定位置浮动
- //右下角
- $("#id").floatdiv("rightbottom");
- //左下角
- $("#id").floatdiv("leftbottom");
- //右下角
- $("#id").floatdiv("rightbottom");
- //左上角
- $("#id").floatdiv("lefttop");
- //右上角
- $("#id").floatdiv("righttop");
- //居中
- $("#id").floatdiv("middle");
- 另外新添加了四个新的固定位置方法
- middletop(居中置顶)、middlebottom(居中置低)、leftmiddle、rightmiddle
- 3 自定义位置浮动
- $("#id").floatdiv({left:"10px",top:"10px"});
- 以上参数,设置浮动层在left 10个像素,top 10个像素的位置
- */
- jQuery.fn.floatdiv=function(location){
- //判断浏览器版本
- var isIE6=false;
- var Sys = {};
- var ua = navigator.userAgent.toLowerCase();
- var s;
- (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
- if(Sys.ie && Sys.ie=="6.0"){
- isIE6=true;
- }
- var windowWidth,windowHeight;//窗口的高和宽
- //取得窗口的高和宽
- if (self.innerHeight) {
- windowWidth=self.innerWidth;
- windowHeight=self.innerHeight;
- }else if (document.documentElement&&document.documentElement.clientHeight) {
- windowWidth=document.documentElement.clientWidth;
- windowHeight=document.documentElement.clientHeight;
- } else if (document.body) {
- windowWidth=document.body.clientWidth;
- windowHeight=document.body.clientHeight;
- }
- return this.each(function(){
- var loc;//层的绝对定位位置
- var wrap=$("<div></div>");
- var top=-1;
- if(location==undefined || location.constructor == String){
- switch(location){
- case("rightbottom")://右下角
- loc={right:"0px",bottom:"0px"};
- break;
- case("leftbottom")://左下角
- loc={left:"0px",bottom:"0px"};
- break;
- case("lefttop")://左上角
- loc={left:"0px",top:"0px"};
- top=0;
- break;
- case("righttop")://右上角
- loc={right:"0px",top:"0px"};
- top=0;
- break;
- case("middletop")://居中置顶
- loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};
- top=0;
- break;
- case("middlebottom")://居中置低
- loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"};
- break;
- case("leftmiddle")://左边居中
- loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};
- top=windowHeight/2-$(this).height()/2;
- break;
- case("rightmiddle")://右边居中
- loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};
- top=windowHeight/2-$(this).height()/2;
- break;
- case("middle")://居中
- var l=0;//居左
- var t=0;//居上
- l=windowWidth/2-$(this).width()/2;
- t=windowHeight/2-$(this).height()/2;
- top=t;
- loc={left:l+"px",top:t+"px"};
- break;
- default://默认为右下角
- location="rightbottom";
- loc={right:"0px",bottom:"0px"};
- break;
- }
- }else{
- loc=location;
- alert(loc.bottom);
- var str=loc.top;
- //09-11-5修改:加上top为空值时的判断
- if (typeof(str)!= 'undefined'){
- str=str.replace("px","");
- top=str;
- }
- }
- /*fied ie6 css hack*/
- if(isIE6){
- if (top>=0)
- {
- wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
- }else{
- wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
- }
- }
- $("body").append(wrap);
- wrap.css(loc).css({position:"fixed",
- z_index:"999"});
- if (isIE6)
- {
- wrap.css("position","absolute");
- //没有加这个的话,ie6使用表达式时就会发现跳动现象
- //至于为什么要加这个,还有为什么要加nothing.txt这个,偶也不知道,希望知道的同学可以告诉我
- $("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");
- }
- //将要固定的层添加到固定层里
- $(this).appendTo(wrap);
- });
- };
下载地址:http://files.cnblogs.com/regedit/jquery.floatdiv.rar
原文网址:http://www.cnblogs.com/regedit/archive/2008/03/11/1100170.html
广告位