如何在 razor 视图引擎中使用 jquery 名称语法?
我有一个网页正在转换为剃刀视图引擎。我有这段代码,现在失败了:
if ($("input[@name='exerciseRB']:checked").val() == 'New') {
$("#newExercise").show();
$("#existingExercise").hide();
}
else {
$("#newExercise").hide();
$("#existingExercise").show();
}
它似乎认为@(@name中)是我的mvc剃刀的一部分(而不是简单地获取jquery选择器。错误是“无法解析符号名称”
是这里有什么建议可以让 jquery 和 razor 很好地协同工作吗?
I have a webpage that i am converting to razor view engine. I have this code, which is failing now:
if ($("input[@name='exerciseRB']:checked").val() == 'New') {
$("#newExercise").show();
$("#existingExercise").hide();
}
else {
$("#newExercise").hide();
$("#existingExercise").show();
}
where it seems that it thinks the @ (in @name) is part of my mvc razor (as opposed to simply getting jquery selector. The error is "Can't resolve symbol name"
Is there anything suggestion here to allow jquery and razor to work nicely together?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这个非常具体的情况下,您对属性使用 XPath
@
语法,该语法在 jQuery 中已被弃用(在 jQuery ≥ 1.3 中被完全删除,因此它在较新的版本中不起作用)。这里的解决方案是删除
@
并使用 CSS 属性选择器语法:如果您需要转义任何其他原始
@
符号,请将它们加倍,以便得到@ @
。In this very specific case, you're using the XPath
@
syntax for attributes, which has been deprecated in jQuery (being completely removed in jQuery ≥ 1.3, so it won't work in newer versions).The solution here is to remove the
@
and use the CSS attribute selector syntax:If you need to escape any other raw
@
symbols, double them so you get@@
.我相信@@将是如何在剃刀中转义@符号:
I believe @@ would be how to escape the @ symbol in razor: