頁面應(yīng)用中有時(shí)需要在html標(biāo)簽上存儲更多的數(shù)據(jù), 我們可以通過jquery的data方法來實(shí)現(xiàn), 實(shí)現(xiàn)方法如下
<div data-test="Hello"></div> <script> $(function(){ $("div").data("info",{name:"南昌雅騰",website:"http://www.nayteng.com"}); $("div").data("manager","莊子"); console.log($("div").data('info').name); console.log($("div").data("manager")); console.log($("div").data("test")); }) </script>
讀取效果如下: