Domanda

Non so se scelgo il titolo corretto.

Ecco la mia problema, ho creato un modulo in cui posso mettere il mio JS / CSS (http://img4.hostingpics.net/pics/586674modulejs.png ) E vorrei ottenere l'ID dei miei elementi HTML.SharePoint ti sta aggiungendo qualche tipo di caratteri di matrice agli elementi ID e ognuno di essi sembra simile a questo: ctl40_g_fa43dd10_b395_40e7_98cd_a52585a208c5_Timesheet

Così ho usato per ottenere l'ID nel mio WebPart usando il clientid del mio oggetto.Ecco un esempio di quello che stavo facendo prima di spostare il mio JS in un file separato.(Stavo facendo js / style nel file di webpart ACSX ma ho avuto alcuni problemi e ho dovuto spostare il mio JS / Style in una cartella separata).

js

$("#<%#Timesheet.ClientID%>").find("tbody").find("tr").each(function () {
        if ($(this).attr("data-name") == "timesheetEntryTotal") {
            $(this).before(tr);
            return false;
        }
    });
.

CSS

#<%#Timesheet.ClientID%> > tbody > tr > td {
    height: 30px;
    background-color: #F6F6F6;
}
.

Ma ora che ho spostato il mio JS / CSS in una cartella separata non posso più UTENTE <% ...%>.Quindi come posso ottenere l'ID dei miei elementi adesso?

Aiuto. Grazie in anticipo.

È stato utile?

Soluzione

I've found another solution is to use the HTML5 custom attribute like data-name.

So instead of getting the id like this $("#<%#Timesheet.ClientId%>"), I now do $("table[data-id='Timesheet']")

Same thing for the css selector.

table[data-id="Timesheet"] > tbody > tr > td {
        height: 30px;
        background-color: #F6F6F6;
}

Altri suggerimenti

If you're using jQuery to select element, you could use '$' for ends with.

$("table[id$='Timesheet']")

You could do similar for CSS:

table[id$="Timesheet"] > tbody > tr > td {
    height: 30px;
    background-color: #F6F6F6;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top