Have previously shared a user in the DOM after entering a name automatically with JS split into the first name and the form of jquery plug-ins, due to the needs of the project, a client will be automatically split, but do not need to present the split results to the user's method, so write an independent method, posted to share the exchange with you
Copy Code code as follows:
$.extend ({
Splitname:function (FullName) {
var hyphenated = [' Ouyang ', ' Too history ', ' Duanmu ', ' Officer ', ' Sima ', ' Orient ', ' solitary ', ' nangong ', ' once ', ' wenren ', ' xia-hou ', ' Zhuge ', ' yuchisi ', ' Ram ', ' ' Hector ', ' Dan Tai ', ' Huang Fu ',
' Huizong ', ' Puyang ', ' Gong ye ', ' Uncle Tai ', ' Shen ', ' Gongsun ', ' Murong ', ' Dongsun ', ' clock away ', ' grandson ', ' nonfictional ', ' Fortress ', ' situ ', ' Sainus ', ' sikong ', ' ru Yan ', ' Lu Qiu ', ' che ', ' Shang ',
' Vacant ', ' witch ', ' public West ', ' Zhuan sun ', ' Soil 驷 ', ' Gong Liang ', ' carved lacquer ', ' Le Zheng ', ' kill Father ', ' Guliangzhuan ', ' Tuoba ', ' pinch gu ', ' yuan ', ' Make fox ', ' Duan Gan ', ' bai ', ' Huyan ', ' Dong Guo ', ' South Gate ',
' Goat tongue ', ' micro ', ' Male ', ' Gong Yu ', ' public instrument ', ' according ', ' Gong Zhong ', ' on the public ', ' Public gate ', ' Male mountain ', ' male ', ' left Mound ', ' Male ', ' Simon ', ' Jo ', ' V ', ' male ', ' XI ', ' public ',
' Nam Rong ', ' Dong Li ', ' Orient House ', ' Zhong Chang ', ' Zoshu ', ' sang ', ' Jimo ', ' Da Yu ', ' Chu ';
var vlength = fullname.length;
var lastname = ', FirstName = '; before//Last name, first name
if (Vlength > 2) {
var pretwowords = fullname.substr (0, 2);//Take the first two words named to see if they are in the hyphenated library
if ($.inarray (pretwowords, hyphenated) >-1) {
LastName = Pretwowords;
FirstName = FULLNAME.SUBSTR (2);
}else{
LastName = Fullname.substr (0, 1);
FirstName = FULLNAME.SUBSTR (1);
}
}else if (vlength = = 2) {//Full name only two words, before one for last name, later for name
LastName = Fullname.substr (0, 1);
FirstName = FULLNAME.SUBSTR (1);
}else{
LastName = FullName;
}
return [LastName, FirstName];
}
});