문제

정확한 제목을 선택하는지 모르겠습니다.

여기 내 문제가 있습니다. 내 JS / CSS ( "Nofollow">http://img4.hostingpics.net/pics/586674modulejs.png ) 및 HTML 요소의 ID를 얻고 싶습니다.SharePoint는 내 요소 ID에 일종의 매트릭스 문자를 추가하고 각각의 각각은 다음과 유사합니다. ctl40_g_fa43dd10_b395_40e7_98cd_a52585a208c5_Timesheet

내 항목의 Cliendid를 사용하여 내 웹 파트에서 ID를 얻는 데 사용했습니다.다음은 JS를 별도의 파일로 옮기기 전에 제가 수행 한 것의 예입니다.(WebPart ACSX 파일에서 JS / 스타일을 수행하고 있었지만 몇 가지 문제가 있으며 JS / 스타일을 별도의 폴더로 옮겨야합니다.)

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;
}
.

그러나 이제는 JS / CSS를 별도의 폴더로 옮겼으므로 <% ... %>를 더 이상 사용자가 수 없습니다.그래서 내가 지금 내 요소의 ID를 어떻게 얻을 수 있습니까?

도와주세요. 미리 감사드립니다.

도움이 되었습니까?

해결책

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;
}

다른 팁

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top