分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

jQuery文本值相关操作

发布时间:2023-09-06 02:20责任编辑:顾先生关键词:jQuery

html:给div设置值和获取值,会解析html标签

text:给div设置值和获取值,不会解析html标签

val:获取input里的值

代码如下

<html><head><title></title></head> ???<style> ???????div{ ???????????width:100px; ???????????height:100px; ???????????background:red; ???????????margin-bottom:40px; ???????} ???????????</style> ???<script src="http://code.jquery.com/jquery-latest.js"></script> ???<script> ???????????????$(function(){ ???????????$(‘.cHtml‘).html(‘<p>我是学生</p>‘) ?//会把p标签给解析出来,然后我是学生内容添加到div上 ???????????console.log($(‘.cHtml‘).html())   //$(‘.cHtml‘).html()取出div里的内容
      $(‘.cText‘).text(‘<p>我是学生</p>‘) ??//不会解析标签,会把标签直接添加到div上
      console.log($(‘.cText‘).text()) ?????//$(‘.cText‘).text()取出div里的内容
      $(‘input‘).val(‘124‘) ???????????????//给input框里设置值
      console.log($(‘input‘).val()) })   //取出input框的值

  </script>
<body>
  <div class="cHtml"></div>
   <div class="cText"></div>
  <input />
</body>
</html>

效果图

jQuery文本值相关操作

原文地址:https://www.cnblogs.com/superCwen/p/9886408.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved