Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery到VannilaJS(使用ES6导出函数)_Javascript_Jquery - Fatal编程技术网

Javascript jQuery到VannilaJS(使用ES6导出函数)

Javascript jQuery到VannilaJS(使用ES6导出函数),javascript,jquery,Javascript,Jquery,此脚本将每个单词的第一个字母转换为大写字母,但变量wordContainAt,wordsToIgnore,wordUpperCase中数组中的某些单词除外 使用ES6导出将jQuery中生成的代码重构到Vannila JS时遇到问题 我想我没有很好地理解这个概念,除了不能在函数的范围内得到this对象之外 有人能帮我吗 jQuery $(窗口).on('load',function()){ $.fn.capitalize=函数(){ //要忽略的词语 让wordContainAt='@', w

此脚本将每个单词的第一个字母转换为大写字母,但变量
wordContainAt
wordsToIgnore
wordUpperCase
中数组中的某些单词除外

使用
ES6导出
jQuery
中生成的代码重构到
Vannila JS
时遇到问题

我想我没有很好地理解这个概念,除了不能在函数的范围内得到
this
对象之外

有人能帮我吗

jQuery

$(窗口).on('load',function()){
$.fn.capitalize=函数(){
//要忽略的词语
让wordContainAt='@',
wordsToIgnore=['to','and','the','it','or','that','this'],
wordUpperCase=['S.A','SMS','USA'],
最小长度=2;
函数getWords(str){
如果(str==未定义){
str='abc def';
}否则{
str=str;
}
返回str.match(/\S+\S*/g);
}
这个。每个(函数(){
让words=getWords(this.value);
控制台日志(文字);
$.each(单词、函数(i、单词){
//仅当单词不在忽略列表中或包含在@时才继续
if(word.indexOf(wordContainAt)!=-1){
words[i]=words[i].toLowerCase();
}else if(wordUpperCase.indexOf($.trim(word.toUpperCase())!=-1){
单词[i]=单词[i].toUpperCase();
}else if(wordsToIgnore.indexOf($.trim(word))==-1&$.trim(word.length>minLength){
words[i]=words[i].charAt(0).toUpperCase()+words[i].slice(1).toLowerCase();
}否则{
words[i]=words[i].toLowerCase();
}
});
if(this.value!=''){
this.value=words.join(“”);
}
});
};
//带类的字段。较低
$(文档).on('blur','.lower',函数(){
$(this.capitalize();
}).大写();
});


将jQuery转换为vanilla JS独立于导出。一次只做一件事。有关将JQ转换为JS的参考资料,请参阅。将jQuery转换为vanilla JS独立于导出。一次只做一件事。有关将JQ转换为JS的参考资料,请参阅。