以下是我的MVC剃须刀视图的标记:
<div style="visibility:visible;">
var data = [
{"id":"1", "ui_bgcolor":"Green", "ui_forecolor": "Black"},
{"id":"2", "ui_bgcolor":"Amber", "ui_forecolor": "Black"},
{"id":"3", "ui_bgcolor":"Red", "ui_forecolor": "White"}
]
</div>
<script type="text/javascript">
function SetGradeDLLItemStyling() {
$.each(data, function (i) {
alert(data[i].UIBackgroundColor);
});
}
</script>
我收到$ .data是脚本块中未定义的错误。这有什么不对?
答案 0 :(得分:2)
数据未在脚本块中定义,因此无法使用。
<script type="text/javascript">
var data = [
{"id":"1", "ui_bgcolor":"Green", "ui_forecolor": "Black"},
{"id":"2", "ui_bgcolor":"Amber", "ui_forecolor": "Black"},
{"id":"3", "ui_bgcolor":"Red", "ui_forecolor": "White"}
]
</script>