JS 英文不截断单词截取

摘要:
canRunViewCodeJSsubstr原文:Iwantth

canRun

JS 英文不截断单词截取第1张JS 英文不截断单词截取第2张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">
    functioncustomSubstr(str,br){
        if(br<str.length&&str.charAt(br) != ' ') br=str.indexOf(' ',br);  //判断当前字符非空格,则查找向后第一个空格
        returnstr.substr(0,br);
    }
    varstr = "I want this effect, not that one.";
    document.getElementById('substring').innerHTML = '截取22位:'+customSubstr(str,22);
</script>
</html>

免责声明:文章转载自《JS 英文不截断单词截取》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇iOS CAShapeLayer精讲spring中@Scheduled定时任务执行时间不准确问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

js中访问SqlServer数据库

1 <script language="JavaScript"> 2 //创建数据库对象 3 var objdbConn = new ActiveXObject("ADODB.Connection"); 4 //DSN字符串 5 var strdsn = "Driver={SQL Server};...

JS异步加载,JQ事件不被执行解决方法

一,在我们实现动态生成HTML代码时会出现,使用JQ方法会不被执行,解决方法,如下:使用jquery的委托事件,将该方法委托到页面已经存在的一个节点上 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-...

Nodejs介绍、安装及简单使用

打开Nodejs英文网:https://nodejs.org/en/ 中文网:http://nodejs.cn/ 我们会发现这样一句话: 翻译成中文如下: Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。 Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。 Node.js 的包管理器...

Failed to mount component: template or render function not defined.

在公司下班前提交的代码,夜晚回家pull一把,运行却报错: Failed to mount component: template or render function not defined. 百度翻译:无法安装组件:模板或渲染功能未定义。 什么原因呢?百度了一大圈,有的说需要修改配置文件,有的说需要回退vue-loader版本。。。。。 但是都试了个遍...

火狐浏览器(firefox)中js要注意的问题

1.出现错误调用error方法或者ajax请求了多次,那么极有可能是异步请求的原因。 添加async : false , ->async. 默认是 true,即为异步方式,$.ajax执行后,会继续执行ajax后面的脚本,直到服务器端返回数据后,触发$.ajax里的success方法,这时候执行的是两个线程。 -> async 设置为 fals...

js Dom为页面中的元素绑定键盘或鼠标事件

html鼠标事件 onload 页面加载 onclick 鼠标单击 onmouseover 鼠标移入 onmouseout 鼠标移出 onfocus 获取焦点 onblur 失去焦点 onchange 域的内容改变 在事件触发中,this表示对当前dom对象的引用 1、html事件,在html元素上直接绑定事件 <!DOCTYPE html>...