Avoiding a JavaScript Keyword to Specify a CSS Class Value

C # allows you to reserve a word that will be used as the name of the property using the at sign . eg.

// 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" }

I want to do the same in JavaScript. eg.

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 }, {}, {}, {});
}

Note class: 'FormElement readonly' should set the value of the css class in the jqGrid editing dialog box, but IE errors on the reserved word.

Is there an escape character in JavaScript? #class? @ class? & class? Otherwise, how can I tell jqGrid to set the css class in a popup editor? Thank.

+3
source share
4

, i.e.

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

jqGrid, , "" .

+2

Use "className".

+1
source

You can also use @class in jQuery

0
source

Source: https://habr.com/ru/post/1747127/


All Articles