zoukankan      html  css  js  c++  java
  • 字符练习

    <script type="text/javascript">


    /* indexOf() 用于查找字符串有是否有这个字符,返回索引
    var the_email = prompt("what\'s your email address?","");
    var temp = the_email.indexOf('@');
    if(temp==-1){
    alert("your email have not @ char.");
    }
    */

    /* charAt() 可以返回字串中的某个字符
    var the_word = "monkey";
    var the_last_word = the_word.charAt(the_word.length-1);
    alert(the_last_word); //output y
    */

    /*

    substring() 可以截取一个字串中的几个字符,而不是单个。语法 : substring(form,to) length = to -form, to 的长度是整个字符长度
    var the_string = "monkey";
    var cut_it = the_string.substring(3,4);
    alert(cut_it); //output k
    */


    /*
    var the_string = "http://www.webmonkey.com/javascript/index.html";
    var first_slashes = the_string.indexOf("//");
    // alert(first_slashes); output 5
    var start_domain = first_slashes+2;

    var without_resource = the_string.substring(start_domain,the_string.length);
    // alert(without_resource); output www.webmonkey.com/javascript/index.html
    var sec_slash = without_resource.indexOf("/");
    var domain = without_resource.substring(0,sec_slash);
    alert(domain); //output www.webmonkey.com
    */

    /* split() 将字符转换成数组
    var my_friends ="trixie,moxie,sven,guido,hermes";
    var friend_array = my_friends.split(",");

    for(var i=0;i<friend_array.length;i++){
    document.write(friend_array[i]+"<br/>");
    }
    */

    /*
    var the_string = "http://www.webmonkey.com/javascript/index.html";
    var first_split = the_string.split("//");
    var without_resource = first_split[1];
    var sec_split = without_resource.split("/");
    var domain = sec_split[0];
    alert(domain);
    */

    </script>
  • 相关阅读:
    vue-动画
    vue笔记-路由,组件
    自定义键盘信息
    自定义指令
    vue-笔记2
    轻松搭建基于 Serverless 的文档图片在线转换服务
    轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
    一小时快速搭建基于阿里云容器服务-Kubernetes的Web应用
    阿里云正式推出内容平台“云栖号”:全面助力企业和个人上云决策
    云原生安全-更安全的密文管理 Vault on ACK
  • 原文地址:https://www.cnblogs.com/coolicer/p/2025006.html
Copyright © 2011-2022 走看看