开发者

jQuery selectors with meta-characters

I'm having problem selecting an element with an id like this <li ="0f:Bactidol_Recorder.mp4">.

I tried using the function that escapes meta-characters with two backslashes below from this jquery link but still can't select the element

Function:

function jq(myid) { 
   return '#' + myid.replace(/(:|\.)/g,'\\$1');
}

Example:

$(jq('0fb:Bactidol_R开发者_JAVA技巧ecorder.mp4')).empty()

Output:

$(#0fb\\:Bactidol_Recorder\\.mp4).empty();


EDIT: Your original code works fine. (jQuery 1.4.2)

You could write

$('*[id="0fb:Bactidol_Recorder.mp4"]')

However, it'll be slower.

The fastest way to do this would be to write

$(document.getElementById("0fb:Bactidol_Recorder.mp4"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜