をいただければ幸いです。 keypress
this
はdivNarrative1
を指しており、その上にclosest
を呼び出すと、table
が必要になりません。 this
の代わりにe.target
を使用してください。
$(document).ready(function() {
$("#divNarrative1").keypress(function(e){
alert(e.target.id);
var msgId = $(e.target).closest('table').attr('id');
alert(msgId);
});
});
更新:ページ上の相続人は、HTML
012テーブル // Insert HTML table
function InsertTable() {
var div = document.getElementById('divNarrative1'); // table reference
div.focus();
document.getElementById("hfProjectBoxNumber").value = Number(document.getElementById("hfProjectBoxNumber").value)+ 1;
document.getElementById("hfBillTextNumber").value = Number(document.getElementById("hfBillTextNumber").value)+ 1;
var projdiv = "Projectbox" + document.getElementById("hfProjectBoxNumber").value
//create table
var tbl = document.createElement('table');
tbl.id = projdiv;
tbl.width = "570px";
tbl.setAttribute("table-layout", "fixed");
tbl.setAttribute("border", "1");
tbl.setAttribute("height", "50px");
tbl.border = 1;
//create header row
var oRow = tbl.insertRow(-1);
var oCell = oRow.insertCell(-1);
oCell.width = "570px";
oCell.setAttribute("colspan", "2");
oCell.setAttribute("align", "center");
oCell.innerHTML = projdiv;
//create coumns
var oRow = tbl.insertRow(-1);
var oCell = oRow.insertCell(-1);
oCell.width = "430px";
oCell.innerHTML = "DESCRIPTION";
oCell.setAttribute("align", "center");
var oCell2 = oRow.insertCell(-1);
oCell2.width = "140px";
oCell2.innerHTML = "AMOUNT";
oCell.setAttribute("align", "center");
div.appendChild(tbl);
return false;
}
を作成相続人
OPによってJS
</div>
<asp:Button ID="btnEditNarr" runat="server" Text="Edit Narrative" />
<input type="button" value="Clear all Content" onclick="clearBilltextbox();"/>
<input type="button" value="Save Content" onclick="getallcontent();"/>
</asp:Panel>
テーブルが定義されていないと言っていますか( '$(this).closest( 'table')が定義されていません)か、またはidが未定義です(' msgId is undefined')?あなたのHTMLは何ですか? –
見たいマークアップを教えてください。 – Gabe
HTMLの外観はどうですか?私の推測では、#divNarrative1はテーブル内にないので、 'closest'はDOMをトラバースする適切な方法ではありません。 – tvanfosson