Javascript 在站点上创建大型工具提示词汇表,使用编辑器的快捷码?jQuery是正确的解决方案吗?
在wordpress上建立一个爱好网站。Said hobby有一个大的(几百个)术语,可能会在页面中多次出现,其中包含用户可能想调用的某些信息,因此我实现了一个插件,用于在鼠标悬停时显示工具提示 然而,由于想法是最终扩展站点,以便其他非开发人员可以添加内容;我想要一个用户友好的方式,让他们能够插入工具提示,因为他们正在写 现在,工具提示仅出现在如下段落中:Javascript 在站点上创建大型工具提示词汇表,使用编辑器的快捷码?jQuery是正确的解决方案吗?,javascript,php,jquery,wordpress,tooltip,Javascript,Php,Jquery,Wordpress,Tooltip,在wordpress上建立一个爱好网站。Said hobby有一个大的(几百个)术语,可能会在页面中多次出现,其中包含用户可能想调用的某些信息,因此我实现了一个插件,用于在鼠标悬停时显示工具提示 然而,由于想法是最终扩展站点,以便其他非开发人员可以添加内容;我想要一个用户友好的方式,让他们能够插入工具提示,因为他们正在写 现在,工具提示仅出现在如下段落中: <p>This is my paragraph with a certain <span class="tooltip"
<p>This is my paragraph with a certain <span class="tooltip" data-tooltip-content="#Three_Word_Term">Three Word Term</span> in it. When it's hovered the tooltip displays. </p>
这是我的一段话,里面有一个三个词。悬停时,将显示工具提示
理想情况下,我会使用一些简单的短代码,这样他们就可以用一个{!三个单词的术语}写一个句子。这就是他们最后要做的
因此,我试图想出一种方法,基本上抓取{!Text String},并用span和class info替换它,再加上一个与它拾取的文本字符串ID=“Text_String”匹配的ID。具体地说,我试图避免定义每个术语以及它将被替换为什么,但是让它自动从{!*}(或类似的东西)之间获取术语,并在替换位中重用它
我认为这是可以用jQuery实现的?我知道我可以找到并替换,我只是不知道我是否可以在某些标记之间“找到”文本,然后在替换中重用它
还不知道jQuery是否是解决这一问题的最佳/最干净的解决方案?我绝对是一个初学者,只是边走边教自己,所以非常感谢您的帮助。如果我理解您的要求。。。您希望用户输入一个文本,如:
<p id="myP">This is my paragraph with a certain {!Three Word Term} in it. When it's hovered the tooltip displays.</p>
如果上面匹配了模式,现在可以使用一些字符串方法来处理找到的术语
var textToReplaceEnteredText = "";
// ... do some stuff with the foundText and enteredText strings above
// ... use those to build the textToReplaceEnteredText string
// ... I'll let you work this out. You may want to use the .replace method of strings
// Finally, use jQuery's .html method again, to replace the paragraph's HTML text
$("#myP").html( textToReplaceEnteredText );
var foundText = "";
if( enteredText.match( myRegex ) != null)
foundText = enteredText.match( myRegex )[0];
var textToReplaceEnteredText = "";
// ... do some stuff with the foundText and enteredText strings above
// ... use those to build the textToReplaceEnteredText string
// ... I'll let you work this out. You may want to use the .replace method of strings
// Finally, use jQuery's .html method again, to replace the paragraph's HTML text
$("#myP").html( textToReplaceEnteredText );