JavaScript
这家伙很懒,还没填写该栏目的介绍呢~
阅读(93)
评论(0)
JavaScript已进行时间显示。和倒计时相反。
阅读(844)
评论(0)
<script type="text/javascript">
var targetProtocol = "https:";
if (window.location.protocol != targetProtocol)
window.location.href = targetProtocol +
window.location.href.substring(window.location.protocol.length);
</script>
阅读(1359)
评论(0)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<span id="timespan"></span>
</body>
</html>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script>
var starttime = new Date("2020/11/20");
setInterval(function () {
var nowtime = new Date();
var time = starttime - nowtime;
var day = parseInt(time / 1000 / 60 / 60 / 24);
var hour = parseInt(time / 1000 / 60 / 60 % 24);
var minute = parseInt(time / 1000 / 60 % 60);
var seconds = parseInt(time / 1000 % 60);
$("#timespan").html(day + "天" + hour + "小时" + minute + "分钟" + seconds + "秒");
}, 1000);
</script>
阅读(1022)
评论(0)
js 判断字符串中是否包含某个字符串
String对象的方法
方法一: indexOf() (推荐)
var str = "123";
console.log(str.indexOf("3") != -1 ); // true
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。如果要检索的字符串值没有出现,则该方法返回 -1。
方法二: search()
var str = "123";
console.log(str.search("3") != -1 ); // true
search() 方法用于检索字符串中指定的子字符串,或检索与正则表达式相匹配的子字符串。如果没有找到任何匹配的子串,则返回 -1。
方法三:match()
var str = "123"; var reg = RegExp(/3/); if(str.match(reg)){ // 包含 }
match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。
RegExp 对象方法
方法四:test()
var str = "123"; var reg = RegExp(/3/);
console.log(reg.test(str)); // true
test() 方法用于检索字符串中指定的值。返回 true 或 false。
方法五:exec()
var str = "123"; var reg = RegExp(/3/); if(reg.exec(str)){ // 包含 }
exec() 方法用于检索字符串中的正则表达式的匹配。返回一个数组,其中存放匹配的结果。如果未找到匹配,则返回值为 null。
阅读(1093)
评论(0)
很多的时候,我们需要用javascript来实现倒计时和已过时。这段代码经过实践,非常的不错