jQuery @运营商?
所以我有别人的旧代码,我试图恢复。我对jQuery不太熟悉,但是运算符指定了什么?jQuery @运营商?
的代码是:
v_button_format = $('#' + v_form_id).find('input[@name=button_format]').val();
v_content_type = $('#' + v_form_id).find('input[@name=content_type]').val();
我使用jQuery 1.3和它抛出 “未捕获的异常:语法错误,无法识别的表达式:[@名称= button_format]” 的错误。是否存在兼容性问题?
这是一个属性选择器。
的@
是XPath主义即不再jQuery中使用。
此外,新版本的jQuery要求属性值用引号引起来。
因此,你应该写
$('#' + v_form_id).find('input[name="content_type"]').val();
这意味着attribute
。 input[@name=button_format]
表示the input tag with the name attribute equal to button_format
。
但是,您需要删除最近版本中的@和quote button_format。这意味着@
不向后兼容。 So quoth the docs。
注:在jQuery的1.3 [@attr]除去的样式选择器(它们先前在jQuery 1.2中建议使用)。只需从选择器中删除“@”符号,以便再次使用它们。
感谢关于“@”的提示! – powtac
input[@name=button_format]
意味着名称属性设置为 'button_format' 的输入字段,即:
<input name="button_format">
input[@name=button_format]
这是旧选择 type.please删除,如果@如果使用jQuery最新版本 新的方式是
input[name="button_format"]
注意:在jQuery 1.3 [@attr]样式选择器被删除(它们是 以前在jQuery 1.2中不推荐使用)。只需从选择器中删除'@'符号 以使其再次工作。
这是一个不推荐使用的选择器,您必须将其从代码中移除,因为它不再受支持,并且会导致错误。
这是做它的老样子。
这是一样的(和应改为):
$('input[name="button_format"]')
还要注意强制性报价
属性为他人提及。
我2美分:记号从XPath,它也表示(XML)的启发属性使用@
被@操作与当前的jQuery向后兼容? – powtac
@powtac:我不相信。 – SLaks
很少有话题,但对于这样的事情是不是更好使用'document.getElementsByName'? –