[英]How to get text from <p> tag using JavaScript?
我想在三秒后使用setInterval()
方法更改 p 标签的内容。 三秒后,我想更改p
标签内的内容,新的间隔为 5 秒。 这是我的代码片段:
背景.js
var notify; var word=function(){ $.get("http://localhost/chrome-notification/dosya.php", function (data) { $('#container').html(data); }); }; setInterval(word,3000); setInterval(function(){ $.get("http://localhost/chrome-notification/", function (response) { notify=$(response).getElementsByTagName('p')[0].innerHTML; }); },5000);
index.html
<html lang="en"> <head> <meta charset="UTF-8"> <script language="JavaScript" type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="background.js"></script> <title>Vocabulary</title> </head> <body> <p id="container"> </p> </body> </html>
这可以在纯js中完成。
var text = document.getElementById('container').innerHTML;
这是你需要的吗?
由于您使用的是 jQuery,您可以简单地执行$(response).find('p:eq(0)').html()
如果我理解得很好,我建议添加 CSS 并将其链接到 html。(如果这是您需要的)
在css中制作tag并自定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.