使用javascript构建动态表时,锚链接不起作用。
代码:
$(".genareteEmail").click(
function() {
alert("sdsds");
var incidentNo = $(this).attr('dataId');
$.ajax({
url : "generate?incident=" + incidentNo,
method : 'GET',
success : function(data) {
var subject = data;
var content = subject.split("END");
try {
var outlookApp = new ActiveXObject(
"Outlook.Application");
var nameSpace = outlookApp
.getNameSpace("MAPI");
mailFolder = nameSpace
.getDefaultFolder(6);
mailItem = mailFolder.Items
.add('IPM.Note.FormA');
mailItem.Subject = content[3];
mailItem.cc = content[2];
mailItem.To = content[1];
mailItem.HTMLBody += content[0];
var insp = mailItem.GetInspector;
var mySigline = mailItem.HTMLBody;
mailItem.display(0);
} catch (e) {
alert(e);
// act on any error that you get
}
}
});
});
$("#btnSubmit").click(function(){
callMe();
});
function callMe() {
$.ajax({
url : "ajaxTicketInfo",
type : 'GET',
error : function() {
},
success : function(result) {
var ticketCount = result.length;
var mytable = $('<table></table>');//.attr({ id: "basicTable" });
var rows = ticketCount;
var cols = 2;
var tr = [];
$('<tr></tr>').html("<th>Incidents</th><th>Mail Generation</th>").appendTo(mytable);
for (var i = 0; i < rows; i++) {
var row = $('<tr></tr>').appendTo(mytable);
for (var j = 0; j < cols; j++) {
if(j== 0){
$('<td></td>').text(result[i] + " "+ Math.random()).appendTo(row);
}else{
//var aTag = $('<a></a>').attr({ dataId: result[i] });
$('<td></td>').html('<a class="genareteEmail" href="#" dataId ="'+result[i]+'">Generate Email</a>').appendTo(row);
/* $('<td></td>').text("Generate Mail").append(row); */
}
}
}
$("#box").html(mytable);
},
cache: false
});
};
setInterval(callMe, 900000);
});
<body>
<h1>Acknowledgement Mail Generation</h1>
<div>
<div>
Next Refresh will be in <span id="time">05:00</span> minutes!
</div>
<div>
<button id = "btnSubmit">Refresh</button>
</div>
</div>
HTML代码:
<div id="box">
<table>
<tbody>
<tr><th>Incidents</th><th>Mail Generation</th></tr>
<tr><td>INC000013610276 0.15926314527814805</td><td>
<a class="generateEmail" href="#" dataid="INC000013610276">Generate
Email</a></td></tr>
<tr><td>INC000013608353 0.7894190043310691</td><td>
<a class="generateEmail" href="#" dataid="INC000013608353">Generate
Email</a></td></tr>
<tr><td>INC000013594620 0.8572899023472066</td><td>
<a class="generateEmail" href="#" dataid="INC000013594620">Generate
Email</a></td></tr>
<tr><td>INC000013592053 0.02202170976246076</td><td>
<a class="generateEmail" href="#" dataid="INC000013592053">Generate Email</a>
</td>
</tr>
</tbody>
</table>
</div>
根据我的代码,当我点击相应的锚链接时,需要执行.genarateEmail jquery。但点击功能无效。
在创建动态表时,任何人都可以帮我解决问题。
答案 0 :(得分:0)
文档准备好后,所有事件都应该绑定。因此,在@Mark B评论的文档中包含您的方法
$(document).ready(function(){
$(".genareteEmail").click( function(){
//Your logic
})
})