共计 753 个字符,预计需要花费 2 分钟才能阅读完成。
html(val) 方法获取第一个匹配元素的 html 内容 (innerHTML)。此属性在 XML 文档上不可用。
html() – 语法
selector.html( )
html() – 示例
以下是一个简单的示例,简单说明了此方法的用法 -
The jQuery Example
type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
type="text/javascript" language="javascript">
$(document).ready(function() {
$("div").click(function () {
var content=$(this).html();
$("#result").html(content);
});
});
.div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
Click on any square below to see the result:
id="result"> THIS IS TEST
class="div" style="background-color:blue;">
This is square one
class="div" style="background-color:green;">
This is square two
class="div" style="background-color:red;">
This is square three
这将产生以下输出 -
参考链接
https://www.learnfk.com/jquery/dom-html.html
原文地址: 无涯教程 -jQuery – html() 方法函数
正文完