1 <script type="text/javascript"> 2 var getString=function(fileName){ 3 return fileName.split(".").pop(); 4 } 5 //例1 6 var fileName1 = "photo.jpg"; 7 var getString1 = getString(fileName1); // 获取值 jpg 8 alert(getString1); 9 10 //例2 11 var fileName2 = "main.js"; 12 var getString2 = getString(fileName2); // 获取值 js 13 alert(getString2); 14 </script>
时间: 2024-11-05 22:49:30