2011-09-01 68 views
2

为什么会返回错误?获取链接标记返回错误

<link rel="shortcut icon" type="image/x-icon" href="gfx/favicon.ico" /> 

var link = $('link[rel=shortcut icon]'); 

错误:

uncaught exception: Syntax error, unrecognized expression: [rel=shortcut icon] 

回答

3

你需要把价值rel引号:

var link = $('link[rel="shortcut icon"]'); 

jQuery docs的属性选择:

jQuery('[attribute="value"]')

attribute An attribute name.

value An attribute value. Quotes are mandatory.

相关问题