[英]jQuery.data() version compatibility and HTML5 data attributes
我正在使用HTML5數據屬性在圖像上設置兩個數據值。 jQuery 1.5.2可以正確地讀回它們,但是使用jQuery 1.7.2時,兩個值的定義都變得不確定。
jsFiddle示例: http : //jsfiddle.net/rupw/SpEDb/
我檢查了http://api.jquery.com/data/的文檔。假設在v1.7.2中應該使用相同的數據檢索方式
任何專家都可以指出什么是不兼容的嗎?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
$(document).ready(function() {
//it works in jquery 1.5.2, but not 1.7.2
$('img.tip').tooltip();
});
<img class="tip" data-tipHeader="Easy" data-tipBody="Very easy." src="a.gif" />
(function($) {
$.fn.tooltip = function(options) {
this.each(function() {
var $this = $(this);
var tipHeader = $this.data('tipHeader');
var tipBody = $this.data('tipBody');
$this.hover(function(e) {
根據我的研究,請勿在html data- *屬性名稱中使用大寫字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.