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>
  • 相关阅读:
    处在什么都想学,却又不知道怎么学的处境
    启动MongoDB shell客户端会什么会一闪而过
    Socket.io发送消息含义
    轮询、长轮询与Web Socket的前端实现
    org.apache.commons.lang3.StringUtils类中isBlank和isEmpty方法的区别
    JS学习笔记10_Ajax
    JS学习笔记9_JSON
    JS学习笔记8_错误处理
    JS学习笔记7_表单脚本
    JS学习笔记6_事件
  • 原文地址:https://www.cnblogs.com/coolicer/p/2025006.html
Copyright © 2011-2022 走看看