本教程操作环境:windows10系统、jquery3.4.1版本、dell g3电脑。
jquery调用html页面内容html() 方法设置或返回被选元素的内容(innerhtml)。
当该方法用于返回内容时,则返回第一个匹配元素的内容。
当该方法用于设置内容时,则重写所有匹配元素的内容。
语法为:
返回内容:
$(selector).html()
设置内容:
$(selector).html(content)
示例如下:
<!doctype html><html><head><meta charset="utf-8"><title></title><script src="jquery/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){alert($("p").html());});});</script></head><body><button>获取这个p元素的内容</button><p>这是一个 <b>段落</b>。</p></body></html>
输出结果:
点击按钮后:
视频教程推荐:jquery视频教程
以上就是jquery能调用获取html页面内容吗的详细内容。
