使用text方法获取Html元素文本信息示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

使用text方法获取Html元素文本信息示例

  2020-05-13 我要评论

获取文本信息的方法有很多,本例使用的使用的是jquery的text方法,这个方法想必大家都有使用过吧,简单实用。获取之后并使用alert将文本弹出,下面是实现代码

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 <style> 
 p { margin:8px; font-size:20px; color:blue;  
   cursor:pointer; } 
 b { text-decoration:underline; } 
 button { cursor:pointer; } 
 </style> 
  <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> 
</head> 
<body> 
   
<b>Show My Text</b> 
<div id="TEXT"></div> 
  
<script> 
$("#TEXT").load("qqq.txt", function(response, status, xhr) { 
var text=$(this).text(); 
 alert( text); 
}); 
 </script> 
</body> 
</html>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们