Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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
Jquery g、 功能(m){ 返回m.toUpperCase(); }); }); a::before{ 内容:attr(title); }_Jquery_Html_Css - Fatal编程技术网

Jquery g、 功能(m){ 返回m.toUpperCase(); }); }); a::before{ 内容:attr(title); }

Jquery g、 功能(m){ 返回m.toUpperCase(); }); }); a::before{ 内容:attr(title); },jquery,html,css,Jquery,Html,Css,这不能在CSS中完成,因为CSS只改变HTML的表示,而不改变底层数据或属性。因此,JavaScript是这种情况下的唯一解决方案。为此,我建议: // retrieving all elements with a title-attribute, using // document.querySelectorAll(), and converting that into an Array // using Array.from. // we then use Array.prototype.f

这不能在CSS中完成,因为CSS只改变HTML的表示,而不改变底层数据或属性。因此,JavaScript是这种情况下的唯一解决方案。为此,我建议:

// retrieving all elements with a title-attribute, using
// document.querySelectorAll(), and converting that into an Array
// using Array.from.
// we then use Array.prototype.forEach() to iterate over each of
// those nodes:
Array.from(document.querySelectorAll('[title]')).forEach(function(el) {
  // 'el' (the first argument) is the current Array-element of the
  // Array over which we're iterating.

  // here we use String.prototype.replace() to replace a the
  // captured string `[a-z]` (lower-case only) which follows a
  // a word-boundary (`\b`) finding all matches (g) from the supplied
  // string, and using the anonymous function of the replace() method:
  return el.title = el.title.replace(/\b([a-z])/g, function(m){

    // here we return the match ('m') once we've converted it
    // to uppercase using String.prototype.toUpperCase():
    return m.toUpperCase();
  });
});
Array.from(document.querySelectorAll('[title]')).forEach(函数(el){
返回el.title=el.title.replace(/\b([a-z])/g,函数(m){
返回m.toUpperCase();
});
});
a::before{
内容:attr(title);
}

非常酷的更换解决方案!只是用
querySelector
而不是
queryselectoral
:)打错了,我在验证阶段就发现了。非常酷的替换解决方案!只是输入了
querySelector
而不是
queryselectoral
:)是的,我在验证阶段发现了这一点。
<a href="#" title="This Is Title Capitalize">
var elems = document.getElementsByTagName('a');

for (el in elems) {
    if (el.hasAttribute('title') {
        var str = el.getAttribute('title');
        str = titleCase(str);
        el.setAttribute('title', str);
    }
}

function titleCase(str) {  
  str = str.toLowerCase().split(' ');

  for(var i = 0; i < str.length; i++){
    str[i] = str[i].split('');
    str[i][0] = str[i][0].toUpperCase(); 
    str[i] = str[i].join('');
  }
  return str.join(' ');
}
<script>
(function() {
  [].forEach.call(document.querySelectorAll('[title]'), function(element) {
    var words = element.title.split(/\s+/);
    var capitalized = words.map(function(word) {
      return word[ 0 ].toUpperCase() + word.slice(1);
    });
    element.title = capitalized.join(' ');
  });
})();
</script>
// retrieving all elements with a title-attribute, using
// document.querySelectorAll(), and converting that into an Array
// using Array.from.
// we then use Array.prototype.forEach() to iterate over each of
// those nodes:
Array.from(document.querySelectorAll('[title]')).forEach(function(el) {
  // 'el' (the first argument) is the current Array-element of the
  // Array over which we're iterating.

  // here we use String.prototype.replace() to replace a the
  // captured string `[a-z]` (lower-case only) which follows a
  // a word-boundary (`\b`) finding all matches (g) from the supplied
  // string, and using the anonymous function of the replace() method:
  return el.title = el.title.replace(/\b([a-z])/g, function(m){

    // here we return the match ('m') once we've converted it
    // to uppercase using String.prototype.toUpperCase():
    return m.toUpperCase();
  });
});