JavaScript 字符串和日期内容整理

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<script type="application/javascript">

var quanj = '全局变量';

alert('提示');


test();
function test()
{
    jub = '局部变量';
    
    alert('函数里的提示' + quanj + ' ' + jub);
}

function test1(var1, var2)
{
    try{
    var a = var1 + var2 + jub;
    }
    catch(ex)
    {
        alert(ex.message)
    }
    alert(a);

}

function test2(danj, shul)
{
    return danj * shul;
}

var b = test2(5,20);

alert('金额 = ' + b);



</script>
</head>

<body>

<input type="button" value="按钮" onclick="test1(1,2);"/>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<script type="application/javascript">

var b = 'zxczxc的长度'.length;

alert('字符串长度' + b);

alert('字符串的查找 = ' + 'abcdef'.indexOf('g'));

alert('字符串的查找 = ' + 'abcdedf'.lastIndexOf('d'));

alert('字符串的截取substr = ' + 'abcdedf'.substr(2,3));

alert('字符串的截取substring = ' + 'abcdedf'.substring(2,3));

alert('字符串的替换 = ' + 'abcdedf'.replace('de','00'));

var sz = '2015-11-13'.split('-');

for(i = 0; i < sz.length; i++)
{
    alert('sz = ' + sz[i]);
}

var dt = new Date(2015,0,1,1,1,15);

alert(dt.getFullYear() + '-' + dt.getMonth() + '-' + dt.getDate() + '-' + dt.getHours() + '-' + dt.getMinutes() + '-' + dt.getSeconds() + '-' + dt.getDay())

alert(dt);
</script>
</head>

<body>

<input type="button" value="打开新窗口" onclick="window.open('http://www.facebook.com','脸谱','width=600,height=400,top=50,left=100,scrollbars=yes,resizeable=yes,toolbar=yes,menubar=yes,location=yes');" />

<input type="button" value="关闭窗口" onclick="window.close();"/>
</body>
</html>
原文地址:https://www.cnblogs.com/shadowduke/p/4963616.html