canRun

View Code
<html>
<head>
    <title>JS substr</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="zh-CN" />
</head>
<body>
</body>
<div>原文:I want this effect, not that one.</div>
<div id="substring"></div>
<script type="text/javascript">
    function customSubstr(str,br){
        if(br<str.length&&str.charAt(br) != ' ') br=str.indexOf(' ',br);  //判断当前字符非空格,则查找向后第一个空格
        return str.substr(0,br);
    }
    var str = "I want this effect, not that one.";
    document.getElementById('substring').innerHTML = '截取22位:'+customSubstr(str,22);
</script>
</html>

相关文章:

  • 2021-12-02
  • 2021-11-25
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-02-03
猜你喜欢
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-03-09
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案