从标题到数据 – *由jQuery?

我有一个div元素

blahblahblah

在魔术jQuery脚本之后,我希望它会像那样

 
blahblahblah

所以我试着用这个来操纵

  $( document ).ready(function() { $("[title*='space']").each(function() { var title = $(this).attr('title'); var titleArray = title.split(" "); $(this).attr("data-enter", titleArray[1]); $(this).attr("data-exit", titleArray[2]); $(this).attr("data-duration", titleArray[3]); $(this).removeAttr('title'); }); });  

但它没有正常工作,因为我有data-exit =“fadeOut scaleOut”有两个属性,我的脚本是为div那样的

 
blahblahblah

但我不想要它。 也许你知道这个例子的正确解决方案。 也许一些find或replaceWith函数会对此有所帮助。 谢谢。 我希望你理解我的问题。

我认为这是正则表达式的工作。 像这样的东西:

 $("[title*='space']").each(function() { var title = this.title, enter = this.title.match(/enter=(.*?)(\s|$)/), exit = this.title.match(/exit=(.*?)(\s|$)/), duration = this.title.match(/dur=(.*?)(\s|$)/) $(this).attr("data-enter", enter[1]); $(this).attr("data-exit", exit[1].replace(/,/, ' ')); $(this).attr("data-duration", duration[1]); $(this).removeAttr('title'); }); 
  
blahblahblah