Check out the official blog post on the 1.4.3 release: http://blog.jquery.com/2010/10/16/jquery-143-released/
I am thoroughly confused by this sentence (under "Events"):
jQuery has already had setData and getData events (which are broadcast whenever data is set or gotten through the .data() method) – overriding these methods makes it possible to override the default behavior for those features (namely you can return a different value or prevent a value from being set).
"(...) had setData and getData events (...) - overriding these methods" -- which methods?!?
"makes it possible to override the default behavior" -- how?!? I have looked into the source and I cannot think of any way to either "return a different value" or "prevent a value from being set."
Anyone out 开发者_如何学Cthere who knows more than me?
You can subscribe to these events using the setData
and getData
events:
$(document.body).bind('setData', function(event, key, value) {
console.log(key + ': ' + value);
});
This will log 'example: hello, world' when the following is called:
$('a:first').data('example', 'hello, world');
Unless I am completely misunderstanding how the code works, there is no way to change the default action, including e.preventDefault();
. See the relevant lines in data.js
, the source code for $.fn.data
.
精彩评论