モジュール項目のJSによって要素のIDを取得する
-
10-12-2019 - |
質問
正しいタイトルを選ぶかどうかわかりません。
これは私の問題です、私は私の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 / Styleをやっていましたが、いくつかの問題があり、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;
}