当前位置:网站首页>JS-BOM-名字转换器-输入名字位置颠倒
JS-BOM-名字转换器-输入名字位置颠倒
2022-08-08 14:24:00 【(-^_^-)】
都是string方法 :
使用索引indexOf()
提取字符串:substring()
返回指定位置的字符:charAt()






function hanshu(){
var n =document.getElementById('1');
name=n.value; //名字是文本框中输入的内容
var spaceIndex=name.indexOf(" ");//返回第一个空格所在的索引位置
var firstName=name.substring(0,spaceIndex);//第一个字
var laterName=name.substring(spaceIndex+1);//提取除去第一个空格之后的字
spaceIndex=laterName.indexOf(" ");//返回除去第一个空格所在的索引位置
var SecondName=laterName.substring(0,spaceIndex);//第二个字
var lastName=laterName.substring(spaceIndex+1);
n.value=lastName + " "+SecondName+ " "+firstName;
}边栏推荐
- sample function—R language
- 零基础入门华为云数据库RDS【华为云至简致远】
- 暗恋云匹配匿名交友聊天系统开发
- Talking about the underlying data structure of Redis
- 2022-08-07 The fifth group Gu Xiangquan study notes day31-collection-Map collection
- 现在网上开户安全么?接着证券开户选择哪个证券?
- 【LeetCode】761. Special binary sequence
- Make mistakes small yards artisan study room 】 【 the ladder of the progress of children
- 【低代码】1405- 浅谈低代码平台远程组件加载方案
- [Small Coder Study Room] ABC179-C: It is a miracle that the code does not count down
猜你喜欢

keil5——安装教程附资源包

华为云云数据库RDS MySQL 版初试探【华为云至简致远】

更改C盘用户目录下的用户名(亲测有效)

KMP Media Group South Africa implemented a DMS (Document Management System) to digitize the process, employees can again focus on their actual tasks, providing efficiency

儿子满墙奖状却没考上重点高中,妈妈愤怒撕下痛哭:不读出去打工

【os.path】的相关用法(持更)

暗恋云匹配匿名交友聊天系统开发

TCP补充

什么是发饰hair accessories?

pip install xxx 出现 AttributeError: ‘tuple’ object has no attribute ‘read’ 错误
随机推荐
今日睡眠质量记录83分
shell三剑客-----awk命令
Make mistakes small yards artisan study room 】 【 the ladder of the progress of children
【低代码】1405- 浅谈低代码平台远程组件加载方案
6.【opencv鼠标回调事件】
OpenInfra Days China 2022 |StreamNative 翟佳、刘德志受邀分享
【小码匠自习室】重做ABC250-D, 我无力反抗
更改C盘用户目录下的用户名(亲测有效)
基于Nodejs的医生预约平台的设计和实现
一打是多少个?
a += 1 += 1为什么是错的?
接口测试,
【Personal Summary】2022.8.7 Week End
医学图像数据增强-重采样itk
[Small Coder Study Room] [NOI Online 2020-2 Beginner Group] Finished: Abominable precision will make you burnt
浅学一下二叉树链式存储结构的遍历
什么样的程序员在35岁依然被公司抢着要?打破程序员“中年危机”
【小码匠自习室】ABC180-C: 马虎是小孩的天性吗?
token系统讲解及过期处理
shell三剑客-----sed命令