王新阳

wangxinyang

bootstrap-datetimepicker 详解

http://www.bootcss.com/p/bootstrap-datetimepicker/

需要bootstrap的下拉菜单组件 (dropdowns.less) 的某些样式,还有bootstrap的sprites (sprites.less and associated images) 中的箭头图标。

A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by running build/build_standalone.less through the lessc compiler:

  1. $ lessc build/build_standalone.less datetimepicker.css

所有需要"Date" 的选项都可以处理Date 对象; a String formatted according to the given format; or a timedelta relative to today, eg '-1d', '+6m +1y', etc, where valid units are 'd' (day), 'w' (week), 'm' (month), and 'y' (year).

你也可以指定一个符合 ISO-8601 格式的日期时间,就可以忽略下面的格式:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:ii
  • yyyy-mm-ddThh:ii
  • yyyy-mm-dd hh:ii:ss
  • yyyy-mm-ddThh:ii:ssZ

format

String. 默认值: 'mm/dd/yyyy'

日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。

  • p : meridian in lower case ('am' or 'pm') - according to locale file
  • P : meridian in upper case ('AM' or 'PM') - according to locale file
  • s : seconds without leading zeros
  • ss : seconds, 2 digits with leading zeros
  • i : minutes without leading zeros
  • ii : minutes, 2 digits with leading zeros
  • h : hour without leading zeros - 24-hour format
  • hh : hour, 2 digits with leading zeros - 24-hour format
  • H : hour without leading zeros - 12-hour format
  • HH : hour, 2 digits with leading zeros - 12-hour format
  • d : day of the month without leading zeros
  • dd : day of the month, 2 digits with leading zeros
  • m : numeric representation of month without leading zeros
  • mm : numeric representation of the month, 2 digits with leading zeros
  • M : short textual representation of a month, three letters
  • MM : full textual representation of a month, such as January or March
  • yy : two digit representation of a year
  • yyyy : full numeric representation of a year, 4 digits

weekStart

Integer. 默认值:0

一周从哪一天开始。0(星期日)到6(星期六)

startDate

Date. 默认值:开始时间

The earliest date that may be selected; all earlier dates will be disabled.

endDate

Date. 默认值:结束时间

The latest date that may be selected; all later dates will be disabled.

daysOfWeekDisabled

String, Array. 默认值: '', []

Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6' or [0,6].

autoclose

Boolean. 默认值:false

当选择一个日期之后是否立即关闭此日期时间选择器。

startView

Number, String. 默认值:2, 'month'

日期时间选择器打开之后首先显示的视图。 可接受的值:

  • 0 or 'hour' for the hour view
  • 1 or 'day' for the day view
  • 2 or 'month' for month view (the default)
  • 3 or 'year' for the 12-month overview
  • 4 or 'decade' for the 10-year overview. Useful for date-of-birth datetimepickers.

minView

Number, String. 默认值:0, 'hour'

日期时间选择器所能够提供的最精确的时间选择视图。

maxView

Number, String. 默认值:4, 'decade'

日期时间选择器最高能展示的选择范围视图。

todayBtn

Boolean, "linked". 默认值: false

如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。

todayHighlight

Boolean. 默认值: false

如果为true, 高亮当前日期。

keyboardNavigation

Boolean. 默认值: true

是否允许通过方向键改变日期。

language

String. 默认值: 'en'

The two-letter code of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). Currently ships with English ('en'), German ('de'), Brazilian ('br'), and Spanish ('es') translations, but others can be added (see I18N below). If an unknown language code is given, English will be used.

forceParse

Boolean. 默认值: true

当选择器关闭的时候,是否强制解析输入框中的值。也就是说,当用户在输入框中输入了不正确的日期,选择器将会尽量解析输入的值,并将解析后的正确值按照给定的格式format设置到输入框中。

minuteStep

Number. 默认值: 5

此数值被当做步进值用于构建小时视图。对于每个 minuteStep 都会生成一组预设时间(分钟)用于选择。

pickerReferer : 不建议使用

String. 默认值: 'default' (other value available : 'input')

The referer element to place the picker for the component implementation. If you want to place the picker just under the input field, just specify input.

pickerPosition

String. 默认值: 'bottom-right' (还支持 : 'bottom-left')

此选项当前只在组件实现中提供支持。通过设置选项可以讲选择器放倒输入框下方。

viewSelect

Number or String. 默认值: same as minView (supported values are: 'decade', 'year', 'month', 'day', 'hour')

With this option you can select the view from which the date will be selected. By default it's the last one, however you can choose the first one, so at each click the date will be updated.

showMeridian

Boolean. 默认值: false

This option will enable meridian views for day and hour views.

initialDate

Date or String. 默认值: new Date()

You can initialize the viewer with a date. By default it's now, so you can specify yesterday or today at midnight ...

组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>

带有重置按钮(用于清空输入框)的组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-remove"></i></span>
  4. <span class="add-on"><i class="icon-th"></i></span>
  5. </div>

.datetimepicker(options)

初始化日期时间选择器。

remove

参数: None

移除日期时间选择器。同时移除已经绑定的event、内部绑定的对象和HTML元素。

  1. $('#datetimepicker').datetimepicker('remove');

show

参数: None

显示日期时间选择器。

  1. $('#datetimepicker').datetimepicker('show');

hide

参数: None

隐藏日期时间选择器。

  1. $('#datetimepicker').datetimepicker('hide');

update

参数: None

使用当前输入框中的值更新日期时间选择器。

  1. $('#datetimepicker').datetimepicker('update');

setStartDate

参数:

  • startDate (String)

给日期时间选择器设置一个新的起始日期。

  1. $('#datetimepicker').datetimepicker('setStartDate', '2012-01-01');

Omit startDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setStartDate');
  2. $('#datetimepicker').datetimepicker('setStartDate', null);

setEndDate

参数:

  • endDate (String)

给日期时间选择器设置结束日期。

  1. $('#datetimepicker').datetimepicker('setEndDate', '2012-01-01');

Omit endDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setEndDate');
  2. $('#datetimepicker').datetimepicker('setEndDate', null);

setDaysOfWeekDisabled

参数:

  • daysOfWeekDisabled (String|Array)

Sets the days of week that should be disabled.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', [0,6]);

Omit daysOfWeekDisabled (or provide an otherwise falsey value) to unset the disabled days.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled');
  2. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', null);

Datetimepicker 类暴露了一组event用以对日期进行操作。

show

当选择器显示时被触发。

hide

当选择器隐藏时被触发。

changeDate

当日期被改变时被触发。

  1. $('#date-end')
  2. .datetimepicker()
  3. .on('changeDate', function(ev){
  4. if (ev.date.valueOf() < date-start-display.valueOf()){
  5. ....
  6. }
  7. });

changeYear

当十年视图上的年视图view被改变时触发。

changeMonth

当年视图上的月视图view被改变时触发。

outOfRange

当用户选择的日期超出startDate 或endDate 时,或者通过setDate 或 setUTCDate方法设置日期超出范围时被触发。

日期时间选择器提供了键盘导航:

up, down, left, right 方向键

这些方向键中,left/right 向后/向前 一天,up/down 向后/向前 一周。

配合shift键,up/left 向后退一个月,down/right 向前进一个月。

配置ctrl键,up/left 向后退一年,down/right 向前进一年。

Shift+ctrl 和 ctrl 同等效果 - 也就是说,他们不能同时改变月和年,只能单独改变年。

escape

escape 键可以用来隐藏、重新显示日期时间选择器;当用户希望手工编辑输入框中的值是会很有用。

enter

当选择器处于显示状态时,enter键只是将其隐藏。当选择器处于隐藏状态时,enter键发挥通常的功能 - 提交当前表单,或者其他。

本插件支持月、每周中天的名称、weekStart选项的国际化。默认是语言是English ('en');其它可以使用的翻译文件在js/locales/ 目录中,只需在本插件之后引入需要的语言文件即可。需要增加额外语言支持的话,只需向 $.fn.datetimepicker.dates中增加一个key即可,一定要放在调用 .datetimepicker()之前。如下案例:

  1. $.fn.datetimepicker.dates['en'] = {
  2. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
  3. daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  4. daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
  5. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  6. monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  7. today: "Today"
  8. };

Right-to-left languages may also include rtl: true to make the calendar display appropriately.

If your browser (or those of your users) is displaying characters wrong, chances are the browser is loading the javascript file with a non-unicode encoding. Simply add charset="UTF-8" to your script tag:

  1. <script type="text/javascript" src="bootstrap-datetimepicker.de.js" charset="UTF-8"></script>

绑定输入框,并设置format选项:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker">
  1. $('#datetimepicker').datetimepicker({
  2. format: 'yyyy-mm-dd hh:ii'
  3. });

绑定输入框,并设置format标记:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker" data-date-format="yyyy-mm-dd hh:ii">
  1. $('#datetimepicker').datetimepicker();

作为组件使用:

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input size="16" type="text" value="12-02-2012" readonly>
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>
  1. $('#datetimepicker').datetimepicker();

作为内联日期时间选择器:

  1. <div id="datetimepicker"></div>
  1. $('#datetimepicker').datetimepicker();

js的传值与传址

传值:
var a = 5,b = a;
b = 8;
alert( a);

这时你发现返回5,即a的值根本没有变化,传值是Javascript基本数据类型(数字、字符串、布尔值)被操作的过程,在值被操作过程中,对实际的值做了一份copy,这份copy存在了另一个变量或对象属性或数组元素中,copy的值和原来的值是两份完全独立的值,如果修改了copy的值,那么原值并不会发生改变。

传址:
var obj1=new Object(),obj2 = obj1
obj1.name = "asdsadas";
alert(obj2.name);

这时你会发现返回了asdsadas,可明明修改的是obj1中的name,obj2的name怎么也跟着变化了?传址在Javascript中主要指针对引用类型(对象、数组、函数)的值的操作过程,obj2 = obj1; 这一句将obj1赋值给了obj2,这样也会将原值copy一份放到新变量的空间中,不同的是,这个值的副本实际上是一个指针,指针指向原值的对象,当改变其中任一个变量(或对象的属性)时,另一个的值也会发生变化。


作者:丁小倪
链接:https://www.zhihu.com/question/20133110/answer/14081804

Swiper4.x使用方法

Swiper4.x API文档 http://www.swiper.com.cn/api/index.html

官方演示:https://www.swiper.com.cn/demo/index.html

1.首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件。可下载Swiper文件或使用CDN

<!DOCTYPE html>
<html>
<head>
    ...
    <link rel="stylesheet" href="path/to/swiper.min.css">
</head>
<body>
    ...
    <script src="path/to/swiper.min.js"></script>
</body>
</html>

2.HTML内容。

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
    
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
    
    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
</div>
导航等组件可以放在container之外

3.你可能想要给Swiper定义一个大小,当然不要也行。

.swiper-container {
    width: 600px;
    height: 300px;
}  

4.初始化Swiper:最好是挨着</body>标签

<script>        
  var mySwiper = new Swiper ('.swiper-container', {
    direction: 'vertical',
    loop: true,
    
    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    },
    
    // 如果需要前进后退按钮
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    
    // 如果需要滚动条
    scrollbar: {
      el: '.swiper-scrollbar',
    },
  })        
  </script>
</body>

如果不能写在HTML内容的后面,则需要在页面加载完成后再初始化。

<script type="text/javascript">
window.onload = function() {
  ...
}
</script>

或者这样(Jquery和Zepto)

<script type="text/javascript">
$(document).ready(function () {
 ...
})
</script>

5.完成。恭喜你,现在你的Swiper应该已经能正常切换了。

var Swiper = new Swiper('.swiper-container', {
	autoplay: {
		delay: 3e3, //自动切换的时间间隔
		stopOnLastSlide: false, //切换到最后一个时停止自动切换(loop模式下无效)
		disableOnInteraction: false, //用户操作swiper之后停止自动播放
	},
	effect : 'slide', //切换效果slide/fade/cube/flip
	slidesPerView: 1, //每页slide个数
	spaceBetween: 0, //两个slide的间距
	loop: false, //循环
	//direction : 'horizontal', //滚动方向horizontal/vertical
	//speed:300, //动画持续时间
	pagination: { //分页器
		el: '.swiper-pagination',
		type: 'bullets', //式样bullets/fraction/progressbar
		clickable: true,
	},
	navigation: { //前进后退按钮
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	},
});

Swiper全屏自适应焦点图轮播
https://www.lanrenzhijia.com/banner/6089.html

动态改变每屏slide的数量
1、初始化时设置每屏slide数量为auto。slidesPerView : 'auto'
2、css响应式设置每个slide的宽度 @media(max-width:1399px){ .swiper-slide{width:25%;} }

身份证号码校验

function idCardValid(a) {
    var c, d, e, f, g, h, b = a;
    if ("" === b) return !1;
    if (/^\d{17}[\dXx]$/.test(b) === !1) return !1;
    if (c = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ], d = [ "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" ], 
    e = 0, f = 0, 15 == b.length) {
        for (b = b.substr(0, 6) + "19" + b.substr(6), f = 0; 17 > f; f++) e += b.substr(f, 1) * c[f];
        b += d[e % 11];
    }
    if (g = {
        11:"北京", 12:"天津", 13:"河北", 14:"山西", 15:"内蒙古",
        21:"辽宁", 22:"吉林", 23:"黑龙江",
        31:"上海", 32:"江苏", 33:"浙江", 34:"安徽", 35:"福建", 36:"江西", 37:"山东",
        41:"河南", 42:"湖北", 43:"湖南", 44:"广东", 45:"广西", 46:"海南",
        50:"重庆", 51:"四川", 52:"贵州", 53:"云南", 54:"西藏",
        61:"陕西", 62:"甘肃", 63:"青海", 64:"宁夏", 65:"新疆",
        71:"台湾", 81:"香港", 82:"澳门", 91:"国外"
    }, void 0 == g[b.substr(0, 2)]) return !1;
    if (h = [ b.substr(6, 4), b.substr(10, 2), b.substr(12, 2) ], h.push(new Date(h.join("-"))), 
    h.push(new Date().getFullYear()), h[3].getFullYear() != h[0] || h[3].getMonth() + 1 != h[1] || h[3].getDate() != h[2]) return !1;
    if (h[4] - h[0] < 0 || h[4] - h[0] > 120) return !1;
    if (15 == a.length) return !0;
    for (f = 0; 17 > f; f++) e += b.substr(f, 1) * c[f];
    return d[e % 11] == b.substr(17, 1);
}

使用js获取用户openid

通过自定义菜单打开url,在网页中用js获取用户openid:
一、回复一条图文消息,将用户openid带在链接上
二、认证服务号可以使用高级接口。参考:
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
http://blog.csdn.net/baronyang/article/details/44489841
http://blog.csdn.net/qq_30632003/article/details/52882592

jQueryUI拖拽排序部件 sortable

DEMO  http://jqueryui.com/sortable/

API   http://api.jqueryui.com/sortable/

KindEditor编辑器的bug

1、字体设置为微软雅黑时,内部编码为Microsoft Yahei,带空格,设置失败。
  解决办法:/lang/zh-CN.js 或 kindeditor-all-min.js中把Microsoft Yahei直接替换为中文微软雅黑

2、响应式网站,后台发布新闻等内容时,通常不需要给图片设置宽度和高度,但编辑器图片插件中删除图片宽高中的一项,另一项会变为NaN,
修改kindeditor-all-min.js中的图片插件(或plugins/image/image.js中相应部分):
D.change(function(){J>0&&E.val(Math.round(K/J*parseInt(this.value,10)))}),E.change(function(){K>0&&D.val(Math.round(J/K*parseInt(this.value,10)))})
改为:
D.change(function(){this.value&&J>0&&E.val(Math.round(K/J*parseInt(this.value,10)))}),E.change(function(){this.value&&K>0&&D.val(Math.round(J/K*parseInt(this.value,10)))})

浏览器全屏

function fullscreen(){
    elem=document.body;
    if(elem.webkitRequestFullScreen){
        elem.webkitRequestFullScreen();   
    }else if(elem.mozRequestFullScreen){
        elem.mozRequestFullScreen();
    }else if(elem.requestFullScreen){
        elem.requestFullscreen();
    }else{
        //浏览器不支持全屏API或已被禁用
    }
}

function exitFullscreen(){
    var elem=document;
	$("#fullscreen").show();
    if(elem.webkitCancelFullScreen){
        elem.webkitCancelFullScreen();    
    }else if(elem.mozCancelFullScreen){
        elem.mozCancelFullScreen();
    }else if(elem.cancelFullScreen){
        elem.cancelFullScreen();
    }else if(elem.exitFullscreen){
        elem.exitFullscreen();
    }else{
        //浏览器不支持全屏API或已被禁用
    }
}

js基础知识

WINDOW对象的 postMessage() 方法用于安全地实现跨域通信。
otherWindow.postMessage(message, targetOrigin, [transfer]);

参考:
https://www.w3cschool.cn/fetch_api/fetch_api-lx142x8t.html
https://www.runoob.com/js/met-win-postmessage.html
https://www.jianshu.com/p/ae840f7d7f8b


每一项都是JS中的小技巧,但十分的实用!

1.document.write(""); 输出语句

2.JS中的注释为//

3.传统的HTML文档顺序是:document->html->(head,body)

4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)

5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)

6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();

7.JS中的值类型:String,Number,Boolean,Null,Object,Function

8.JS中的字符型转换成数值型:parseInt(),parseFloat()

9.JS中的数字转换成字符型:("" 变量)

10.JS中的取字符串长度是:(length)

11.JS中的字符与字符相连接使用+号.

12.JS中的比较操作符有:==等于,!=不等于,>,>=,<.<=

13.JS中声明变量使用:var来进行声明

14.JS中的判断语句结构:if(condition){}else{}

15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}

16.循环中止的命令是:break

17.JS中的函数定义:function functionName([parameter],...){statement[s]}

18.当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.

19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self

20.状态栏的设置:window.status="字符";

21.弹出提示信息:window.alert("字符");

22.弹出确认框:window.confirm();

23.弹出输入提示框:window.prompt();

24.指定当前显示链接的位置:window.location.href="URL"

25.取出窗体中的所有表单的数量:document.forms.length

26.关闭文档的输出流:document.close();

27.字符串追加连接符: =

28.创建一个文档元素:document.createElement(),document.createTextNode()

29.得到元素的方法:document.getElementById()

30.设置表单中所有文本型的成员的值为空:

var form = window.document.forms[0]

for (var i = 0; i

if (form.elements[i].type == "text"){

form.elements[i].value = "";

}

}

31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中返回TRUE或FALSE)

32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length

33.单选按钮组判断是否被选中也是用checked.

34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有时用下拉列表框名称加上.selectedIndex来确定被选中的值)

35.字符串的定义:var myString = new String("This is lightsword");

36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();

37.返回字符串2在字符串1中出现的位置:String1.indexOf("String2")!=-1则说明没找到.

38.取字符串中指定位置的一个字符:StringA.charAt(9);

39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);

40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor(value1)小于等于value1的整数,Math.ceil(value1)大于等于value1的整数,Math.random()返回0-1的随机数

41.定义日期型变量:var today = new Date();

42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dateObj.getHours()得到小时,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置月,dateObj.setDate(val)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]

43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName

44.parent代表父亲对象,top代表最顶端对象

45.打开子窗口的父窗口为:opener

46.表示当前所属的位置:this

47.当在超链接中调用JS函数时用:(javascript 来开头后面加函数名

48.在老的浏览器中不执行此JS:< !-- //-- >

49.引用一个文件式的JS:< script type="text/javascript" src="aaa.js" _fcksavedurl=""aaa.js"" _fcksavedurl=""aaa.js"" _fcksavedurl=""aaa.js"" _fcksavedurl=""aaa.js"" >< /script >

50.指定在不支持脚本的浏览器显示的HTML:< noscript >< /noscript >

51.当超链和ONCLICK事件都有时,则老版本的浏览器转向a.html,否则转向b.html.例:< a href="a.html" onclick="location.href='b.html' _fcksavedurl='b.html' _fcksavedurl='b.html' _fcksavedurl='b.html' _fcksavedurl='b.html';return false" >dfsadf< /a >

52.JS的内建对象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError

53.JS中的换行:\n

54.窗口全屏大小:< script >function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;< /script >

55.JS中的all代表其下层的全部元素

56.JS中的焦点顺序:document.getElementByid("表单元素").tabIndex = 1

57.innerHTML的值是表单元素的值:如< p id="para" >"how are < em >you< /em >"< /p >,则innerHTML的值就是:how are < em >you< /em >

58.innerTEXT的值和上面的一样,只不过不会把< em >这种标记显示出来.

59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.

60.isDisabled判断是否为禁止状态.disabled设置禁止状态

61.length取得长度,返回整型数值

62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc

63.window.focus()使当前的窗口在所有窗口之前.

64.blur()指失去焦点.与FOCUS()相反.

65.select()指元素为选中状态.

66.防止用户对文本框中输入文本:onfocus="this.blur()"

67.取出该元素在页面中出现的数量:document.all.tags("div(或其它HTML标记符)").length

68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless()

69.状态栏文字的设置:window.status='文字',默认的状态栏文字设置:window.defaultStatus = '文字.';

70.添加到收藏夹:external.AddFavorite("http://www.webjx.com","jaskdlf");

71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = handleError;

72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener…的多重继续.

73.JS中的self指的是当前的窗口

74.JS中状态栏显示内容:window.status="内容"

75.JS中的top指的是框架集中最顶层的框架

76.JS中关闭当前的窗口:window.close();

77.JS中提出是否确认的框:if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}

78.JS中的窗口重定向:window.navigate("http://www.webjx.com");

79.JS中的打印:window.print()

80.JS中的提示输入框:window.prompt("message","defaultReply");

81.JS中的窗口滚动条:window.scroll(x,y)

82.JS中的窗口滚动到位置:window.scrollby

83.JS中设置时间间隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeout

84.JS中的模态显示在IE4 行,在NN中不行:showModalDialog("URL"[,arguments][,features]);

85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}} window.onbeforeunload=verifyClose;

86.当窗体第一次调用时使用的文件句柄:onload()

87.当窗体关闭时调用的文件句柄:onunload()

88.window.location的属性: protocol(http:),hostname(www.example.com),port(80),host(www.example.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),href(全部的信息)

89.window.location.reload()刷新当前页面.

90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL)

91.document.write()不换行的输出,document.writeln()换行输出

92.document.body.noWrap=true;防止链接文字折行.

93.变量名.charAt(第几位),取该变量的第几位的字符.

94."abc".charCodeAt(第几个),返回第几个字符的ASCii码值.

95.字符串连接:string.concat(string2),或用 =进行连接

96.变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算)

97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置.

98.string.match(regExpression),判断字符是否匹配.

99.string.replace(regExpression,replaceString)替换现有字符串.

100.string.split(分隔符)返回一个数组存储值.

101.string.substr(start[,length])取从第几位到指定长度的字符串.

102.string.toLowerCase()使字符串全部变为小写.

103.string.toUpperCase()使全部字符变为大写.

104.parseInt(string[,radix(代表进制)])强制转换成整型.

105.parseFloat(string[,radix])强制转换成浮点型.

106.isNaN(变量):测试是否为数值型.

107.定义常量的关键字:const,定义变量的关键字:var

108. document.activeElement.id  document.activeElement.tagName  event.currentTarget.id焦点
document.activeElement.id  event.currentTarget.id
IE    支持     不支持
Chrome  不支持    支持
Firefox  支持     支持
<script type="text/javascript">
var show = function (e) {
alert(e.currentTarget?"获取到了 currentTarget":"获取到了 document.activeElement")
//document.activeElements要放到前面,否则IE中会出错(待进一步验证)貌似新版的chrome也支持document.activeElement
alert((document.activeElement || e.currentTarget).id);
};
</script>
<div>案例1:<div>
<div id="div1"><br />
 <a href="javascript:void(0)" id="a1"><img id="img1" src="http://www.google.cn/images/nav_logo3.png" border="0" alt="" onclick="show(event)"/></a>
</div>
<div><br /><br />案例2:</div>
<div id="div2"><br />
 <a href="javascript:void(0)" onclick="show(event)" id='a2'><img id='img2' src="http://www.google.cn/images/nav_logo3.png" border="0" alt=""/></a>
</div>

artDialog 网页对话框插件

http://aui.github.io/artDialog/
2025-04-18 星期五 农历三月二十一