我不知道我是否选择正确的标题。

这是我的问题,我在Wich中创建了一个模块,我可以把我的js / css(http://img4.hostingpics.net/pics/586674modulejs.png ),我想获得我的HTML元素的ID。SharePoint正在为我的元素ID添加某种矩阵字符,并且它们中的每一个都类似于这个:ctl40_g_fa43dd10_b395_40e7_98cd_a52585a208c5_Timesheet 所以我曾经使用我的项目的CliendID获取我的WebPart中的ID。这是我在将JS移动到一个单独的文件之前所做的事情的一个例子。(我在WebPart ACSX文件中正在做JS / SQUE,但我有一些问题,我必须在一个单独的文件夹中移动我的JS / STYLE)。

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移动到一个单独的文件夹,我不能再user <%...%>。那么我现在如何获得我元素的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归因
scroll top