2011-01-28 43 views

回答

0

你的問題可能是jQuery不使用DOM選擇器的「* NS」風格(例如getElementsByTagNamegetElementsByTagNameNS)。

我前段時間寫了一個黑客,用於使用該功能注入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 
    }); 
} 
13

例如這個,

<fb:like href="http://google.com" layout="box_count" show_faces="false" width="450"></fb:like> 


quoted

/* 

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"). 

*/ 

demo

+0

如果您正在設計自己的自定義標籤,您還可以使用與`:`不同的字符,比如````或`_`。 – jpadvo 2012-05-09 20:02:24