Javascript 对jQuery中添加的结果不执行操作
我有一个超链接名称Javascript 对jQuery中添加的结果不执行操作,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我有一个超链接名称它工作正常,它有“从记录到考试取消”的类 请不要注意类名。 接下来的问题是: 当我点击“it works fine”时,它会给我带来很好的效果(在成功操作中更改div),但当我尝试点击按钮时,它刚刚出现在div中,那么我就看不到这个超链接的任何操作(没有!甚至没有警报('alert'))。我如何解决它 <div id='loadingmessage' style=''> loading... </div> <a class="cancel
它工作正常
,它有“从记录到考试取消”的类
请不要注意类名。
接下来的问题是:
当我点击“it works fine”时,它会给我带来很好的效果(在成功操作中更改div),但当我尝试点击按钮时,它刚刚出现在div中,那么我就看不到这个超链接的任何操作(没有!甚至没有警报('alert'))。我如何解决它
<div id='loadingmessage' style=''>
loading...
</div>
<a class="cancel-from-record-to-exam" data-id=19>it works fine</a>
@section Scripts {
<script type="text/javascript">
$("a.cancel-from-record-to-exam").click(function (event) {
alert('alert');
var requestForm = $('#loadingmessage');
$.ajax({
url: '/Test/GetProducts',
contentType: 'application/html; charset=utf-8',
data: { id: $(this).data("id") },
type: 'GET',
dataType: 'html'
})
.success(function (result) {
alert('ok');
requestForm.html('<a class="cancel-from-record-to-exam" data-id=19>here's the new button and it doesn't any actions</a>');
})
.error(function (xhr, status, throwError) {
alert('bad');
})
});
</script>
}
加载。。。
它很好用
@节脚本{
$(“a.cancel-from-record-to-exam”)。单击(函数(事件){
警报(“警报”);
var requestForm=$(“#加载消息”);
$.ajax({
url:“/Test/GetProducts”,
contentType:'application/html;charset=utf-8',
数据:{id:$(this).data(“id”)},
键入:“GET”,
数据类型:“html”
})
.成功(功能(结果){
警报(“正常”);
html('这是新按钮,它不包含任何操作');
})
.错误(功能(xhr、状态、投掷者){
警惕(“坏”);
})
});
}
答案在这里:
$(document).on('click', 'a.cancel-from-record-to-exam', function () {
alert('hehe');
var requestForm = $('#loadingmessage');
$.ajax({
url: '/Test/GetProducts',
contentType: 'application/html; charset=utf-8',
data: { id: $(this).data("id") },
type: 'GET',
dataType: 'html'
})
.success(function (result) {
alert('ok');
requestForm.html('<a class="cancel-from-record-to-exam" data-id=19>heheheheheh</a>');
})
.error(function (xhr, status, throwError) {
alert('bad');
})
});
以下是消息来源:
$(document).on('click', 'a.cancel-from-record-to-exam' , function() {
//code here ....
});