本文翻译自:How to replace innerHTML of a div using jQuery?

How could I achieve the following: 我怎样才能实现以下目标:

document.all.regTitle.innerHTML = 'Hello World';

Using jQuery where regTitle is my div ID? 使用jQuery,其中regTitle是我的div ID?


#1楼

参考:https://stackoom.com/question/5UeC/如何使用jQuery替换div的innerHTML


#2楼

$("#regTitle").html("Hello World");

#3楼

The html() function can take strings of HTML, and will effectively modify the .innerHTML property. html()函数可以接受HTML字符串,并将有效地修改.innerHTML属性。

$('#regTitle').html('Hello World');

However, the text() function will change the (text) value of the specified element, but keep the html structure. 但是, text()函数将更改指定元素的(text)值,但保留html结构。

$('#regTitle').text('Hello world');

#4楼

Here is your answer: 这是你的答案:

//This is the setter of the innerHTML property in jQuery
$('#regTitle').html('Hello World');//This is the getter of the innerHTML property in jQuery
var helloWorld = $('#regTitle').html();

#5楼

jQuery's .html() can be used for setting and getting the contents of matched non empty elements ( innerHTML ). jQuery的.html()可用于设置和获取匹配的非空元素( innerHTML )的内容。

var contents = $(element).html();
$(element).html("insert content into element");

#6楼

Answer: 回答:

$("#regTitle").html('Hello World');

Explanation: 说明:

$ is equivalent to jQuery . $等同于jQuery Both represent the same object in the jQuery library. 两者都代表jQuery库中的相同对象。 The "#regTitle" inside the parenthesis is called the selector which is used by the jQuery library to identify which element(s) of the html DOM (Document Object Model) you want to apply code to. 括号内的"#regTitle"称为选择器 ,jQuery库使用该选择器来标识要应用代码的html DOM(文档对象模型)的哪个元素。 The # before regTitle is telling jQuery that regTitle is the id of an element inside the DOM. regTitle之前的#告诉jQuery regTitle是DOM中元素的id。

From there, the dot notation is used to call the html function which replaces the inner html with whatever parameter you place in-between the parenthesis, which in this case is 'Hello World' . 从那里,点符号用于调用html函数,该函数用括号之间的任何参数替换内部html,在本例中为'Hello World'

如何使用jQuery替换div的innerHTML?相关推荐

  1. jq修改iframe html代码,使用jQuery替换iframe的所有内容(包括doctype和html标签)

    在stackoverflow上还有很多其他帖子提出几乎相同的问题,但在迄今为止我读到的所有答案中,他们没有解决如何实质上替换iframe的整个文档,包括DOCTYPE和html标签.使用jQuery替 ...

  2. c# 替换html注释,C# 替换div标签

    C# 替换div标签0 fillm2013.11.06浏览24次分享举报 e style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc ...

  3. jQuery获取div的背景颜色 How to get background color of div?

    直接代码: <script type="text/javascript"> $(document).ready(function(){$("div" ...

  4. jQuery实现 div里面的文字如何自动缩小,避免文字溢出

    今天用 jQuery实现 div里面的文字如何自动缩小,避免文字溢出的一个例子 代码如下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...

  5. jquery获取div/div之间的内容.text() 和 .html()区别

    jQuery 获取 div 之间的内容,有两种方法,$(selector).text().$(selector).html() . html: <div> <p>test< ...

  6. 通过CSS,Jquery实现DIV的各种动作(包括漂移,未测试IE6)

    此文实现了如下效果: jquery获得窗口高宽,文档高宽值. 通过CSS设置,实现DIV置顶,置底,置左,置右,居中. 利用jquery实现DIV四个方向随滚动条,窗体大小浮动. 一个漂浮反弹的DIV ...

  7. jQuery实现div单选与多选

    jQuery实现div单选与多选 一.单选 1.思想: 先监听所有的div,点击某个div触发事件.如果被点击的div的border是红色,则remove:否则被点击的div的border不是红色,则 ...

  8. jQuery 清除div内容

    jQuery 清除div内容 $.ajax({ url: "SearchSN.aspx", data: "SN=" + $("#txtStorageS ...

  9. jQuery获取div中的内容

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

最新文章

  1. 设计模式-Decorator模式
  2. windows中search driver的顺序
  3. 招聘行业颠覆者【伯小乐】| 手摸手产品研究院
  4. asp.net代码中修改web.config节点
  5. 深入理解Java内存模型(七)——总结
  6. Spring Boot开发之流水无情(二)
  7. IE 8 下面的垂直水平居中
  8. html5星期,HTML5 时钟
  9. GDB 用法和命令介绍
  10. java认证考试题库看不懂_一道JAVA认证考试试题,有点想不通,各位看看...
  11. 2018-10-10 在浏览器插件中读取JSON资源文件
  12. 洛谷 P4147 玉蟾宫 (最大子矩形问题)
  13. 魔兽争霸III—冰封王座6级考试
  14. 关系型数据库-MySQL:授权管理
  15. 东拉西扯01世界的沧海桑田
  16. VC6.0(VC++6.0)使用教程(使用VC6.0编写C语言程序)
  17. 求菲波那切数列第n项
  18. 【那些年我们一起看过的论文】之《ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation》
  19. ZOJ 3952 Fibonacci Sequence Chicken Edition 新构造语言,思路转换
  20. 云顶之弈天选战神劫阵容攻略,天选战神劫如何玩?

热门文章

  1. Android AppCompatCheckBox在低版本上不显示问题
  2. 《From Java To Kotlin》-Kotlin与Java的简单对比
  3. Java时区切换时的需要注意
  4. HIDL示例-JAVA服务创建-Client验证-Android10.0 HwBinder通信原理(四)
  5. 关于android创建快捷方式会启动两个应用的问题(一)
  6. 计算机安装双系统后系统引导修复的方法
  7. IOS开发笔记2-C语言基础复习
  8. HBase在淘宝的应用和优化
  9. 自制php操作mysql工具类(DB.class.php)
  10. 解锁UI自动化新姿势-UI Recorder