2010-05-26 19 views
3

C#允許將保留字用作屬性名稱via the at sign。例如如何「跳過」JavaScript類關鍵字以指定CSS類值

// In ASP.NET MVC, we use @class to define 
// the css class attribute for some HtmlHelper methods. 
var htmlObject = new { readonly = "readonly", @class = "ui-state-highlight" } 

我想在JavaScript中做同樣的事情。例如

function makeGrid(grid, pager) { 
    grid.jqGrid({ 
     caption: 'Configurations', 
     colNames: ['Id', 'Name'], 
     colModel: [ 
      { name: 'Id', index: 'Id' }, 
      { name: 'Name', index: 'Name', editable: true, 
       editoptions: { readonly: 'readonly', class: 'FormElement readonly' } }, 
      ], 
     pager: pager, 
     url: 'www.example.com/app/configurations") %>', 
     editurl: 'www.example.com/app/configurations/edit") %>' 
    }).navGrid(pager, { edit: true, add: false, del: false, search: false }, {}, {}, {}); 
} 

類:「FormElement只讀」應該設置的jqGrid的編輯對話框中的CSS類值,但保留字IE錯誤的。

JavaScript中是否還有轉義字符? #類? @類? & class?否則,我該如何告訴jqGrid在彈出編輯器上設置css類?謝謝。

+0

順便說一句,'@'不是&符號,'&'是&符號(在第一段中)。 – 2012-04-19 13:31:52

+0

感謝鮑里斯,固定 – 2012-04-24 20:01:06

回答

10

我覺得在這種情況下,引用類應該工作,因爲它是一個對象字面上即

editoptions: { readonly: 'readonly', 'class': 'FormElement readonly' } }, 
+0

工程太棒了!謝謝。 – 2010-05-26 05:57:40

2

我不知道jqGrid,但我會想象'類'會工作。

0

您還可以在jQuery的

1

使用「類名」使用@class一個屬性的名稱。