HTML:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sit amet est tempus, fermentum ligula et, hendrerit nisl. Praesent tempor eget quam quis auctor. Vivamus mollis mauris id sem aliquam, vel fermentum neque fringilla. Morbi malesuada accumsan augue ut hendrerit. Aenean commodo vulputate lacinia. Integer at purus eget arcu venenatis consectetur vel sed sem. Mauris quis est id ligula aliquam tempor a nec neque. Donec scelerisque velit ac metus aliquet, in euismod nisl lacinia. Quisque imperdiet gravida facilisis. In hac habitasse platea dictumst. Quisque vel erat congue, consequat libero eget, blandit sapien. Suspendisse potenti. Praesent at mollis purus.</p>
CSS:
.highlight {
color: red;
}
JS:
$(function(){
$('p').click(function(){
// get highlighted words
// get user input
var user_input = window.prompt();
// put highlighted words in <span class="highlight"></span> element
// and add data-id to the span element
// expected output:
// <p>... <span class="highlight" data-id="user input here">highlighted words here</span> ...</p>
});
});
我在标签中有一段文本,p
我希望它是这样的:
- 用户选择块内的一些单词
- 用户在提示框中输入内容
- 将突出显示的单词放在
span
带有 data-attribute 的标签内(我称之为它data-id
),这个 data-attribute 值来自提示(上面的步骤 2)
我如何实现这一目标?
请帮我。