FBML使用標籤,如<fb:like></fb:like> <fb:board></fb:board>
等。使用jQuery選擇自定義FBML樣標籤
他們是如何選擇這些?我試過$('fb')
和$('fb:like')
,都返回一個空對象...有誰知道這可以做和?
FBML使用標籤,如<fb:like></fb:like> <fb:board></fb:board>
等。使用jQuery選擇自定義FBML樣標籤
他們是如何選擇這些?我試過$('fb')
和$('fb:like')
,都返回一個空對象...有誰知道這可以做和?
你的問題可能是jQuery不使用DOM選擇器的「* NS」風格(例如getElementsByTagName
與getElementsByTagNameNS
)。
我前段時間寫了一個黑客,用於使用該功能注入jQuery(特別是對於XHTML上下文)。你也許可以把它調整到你自己的需要:
https://gist.github.com/352210
/**
* Hack to allow jQuery to work within XHTML documents that define an xmlns
*/
/**
* Use the given object to override the given methods in its prototype
* with namespace-aware equivalents
*/
function addNS(obj, methods) {
var proto = obj.constructor.prototype;
var ns = document.documentElement.namespaceURI;
for (var methodName in methods) {
(function() {
var methodNS = proto[methodName + "NS"];
if (methodNS) {
proto[methodName] = function() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift(ns);
return methodNS.apply(this, args);
};
}
})();
}
}
// Play nice with IE -- who doesn't need this hack in the first place
if (document.constructor) {
// Override document methods that are used by jQuery
addNS(document, {
createElement: 1,
getElementsByTagName: 1
});
// Override element methods that are used by jQuery
addNS(document.createElement("div"), {
getElementsByTagName: 1,
getAttribute: 1,
getAttributeNode: 1,
removeAttribute: 1,
setAttribute: 1
});
}
例如這個,
<fb:like href="http://google.com" layout="box_count" show_faces="false" width="450"></fb:like>
/*
If you wish to use any of the meta-characters
(such as !"#$%&'()*+,./:;[email protected][\]^`{|}~) as a literal part of a name,
you must escape the character with two backslashes: \\. For example,
if you have an an element with id="foo.bar", you can use the selector
$("#foo\\.bar").
*/
如果您正在設計自己的自定義標籤,您還可以使用與`:`不同的字符,比如````或`_`。 – jpadvo 2012-05-09 20:02:24