作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Razor 语法开发 MVC 3 应用程序。
我正在 cshtml 文件中写入 Jscript...我想在 JScript 中使用 @,但它显示黄色背景。
我想将整数值分配给按钮 ID,该怎么做?
这是代码...
success: function (data) {
$("p.p12").append
("<div style=\"background-color:#FAFAFA\";>Recently Added... <br /><a href=\"../../Employee/Details/" + data.OwnerID + "\">" + data.OwnerName + "</a>"
+ data.cmtDateTime + " <span class=\"EmpName\"><button type=\"button\" id = \" @item.Id \"class=\"deleteComment\">Delete</button></span> <br />" + data.msg + "</div>");
document.getElementById('Comment').value = "";
$(".ParentBlock").slideDown("slow");
$(".ParentBlock").attr("DataCommentId",data.Id);
$('.ShowComments').text('Hide Comments');
}
这是图片...
我应该对@符号做什么?
最佳答案
您当前的代码是正确的。运行它,你会发现它可以工作。就黄色曲线而言,忽略它并停止信任自动代码编辑器,相信您编写的代码 - Razor Intellisense 远非完美。希望他们会在未来的版本中改进它。
作为构建此元素的替代方法,您可以使用以下内容,因为您的代码一团糟(例如,属性之间没有空格,您已经颠倒了 ;
和“
,...):
$('p.p12').append(
$('<div/>', {
style: 'background-color:#FAFAFA;',
html: 'Recently Added...'
})
.append($('<br/>'))
.append($('<a/>', {
href: '@Url.Action("Details", "Employee", new { id = "__employeeId__" })'.replace('__employeeId__', data.OwnerID),
html: data.OwnerName
}))
.append(data.cmtDateTime)
.append($('<span/>', {
'class': 'EmpName',
html: $('<button/>', {
type: 'button',
id: '@item.Id',
'class': 'deleteComment',
html: 'Delete'
})
}))
.append($('<br/>'))
.append(data.msg)
);
关于javascript - 如何在 MVC 的 Razor 语法中的 Jscript 中使用 "@"符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12542015/
我是一名优秀的程序员,十分优秀!