close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#imastring{
color: steelBlue;
}
span{
color: darkRed;
}
</style>
</head>
<body>
<h2 id="imastring">我是一個字串I am a string 串</h2>
<h2>我的長度:<span id="length"></span></h2>
<h2>把我弄成大寫:<span id="toUpperCase"></span></h2>
<h2>把我弄成小寫:<span id="toLowerCase"></span></h2>
<h2>我的第三個字是:<span id="charAt3"></span></h2>
<h2>「串」在第幾個字(從0開始算):<span id="indexOf"></span></h2>
<h2>「串」在第幾個字(從結尾開始算):<span id="lastIndexOf"></span></h2>
<h2>從0開始切出6個字:<span id="substring"></span></h2>
<h2>把其中的字取代掉:<span id="replace"></span></h2>
<script type="text/javascript">
var imastring=document.getElementById('imastring').textContent;
document.getElementById('length').innerHTML=imastring.length;
document.getElementById('toUpperCase').innerHTML=imastring.toUpperCase();
document.getElementById('toLowerCase').innerHTML=imastring.toLowerCase();
document.getElementById('charAt3').innerHTML=imastring.charAt(3);
document.getElementById('indexOf').innerHTML=imastring.indexOf('串');
document.getElementById('lastIndexOf').innerHTML=imastring.lastIndexOf('串');
document.getElementById('substring').innerHTML=imastring.substring(0,6);
document.getElementById('replace').innerHTML=imastring.replace('字','串');
</script>
</body>
</html>
全站熱搜
留言列表