Javascript jQuery没有';I don’我不认识阶级的变化
好的,我有一个编辑按钮,当我按下它时,它会变成“完成”按钮 这一切都是由jQuery完成的Javascript jQuery没有';I don’我不认识阶级的变化,javascript,jquery,html,Javascript,Jquery,Html,好的,我有一个编辑按钮,当我按下它时,它会变成“完成”按钮 这一切都是由jQuery完成的 $(".icon-pencil").click(function() { var pencil = $(this); var row = $(this).parent('td').parent('tr'); row.find('td').not(":nth-last-child(2)").not(":last-chil
$(".icon-pencil").click(function() {
var pencil = $(this);
var row = $(this).parent('td').parent('tr');
row.find('td').not(":nth-last-child(2)").not(":last-child").each(function() {
$(this).html("hi");
});
pencil.attr('class', 'icon-ok-sign');
});
// save item
$(".icon-ok-sign").click(function() {
alert("hey");
});
当我按下“编辑”(“.icon pencil
”)按钮时,它的类会变为.icon ok sign
(我可以在chrome控制台中看到)
但当我点击它时,没有显示警报
当我创建一个按钮并按下它时,会显示一个警报
如何解决它?尝试使用$(文档)。在(“单击”、“.icon ok sign”,function(){…
尝试使用$(文档)。在(“单击”、“.icon ok sign”,function(){…
使用以下脚本:
$(document).on('click','.icon-ok-sign',function(){
alert("hey");
});
使用以下脚本:
$(document).on('click','.icon-ok-sign',function(){
alert("hey");
});
这是因为您不能为将来的元素注册单击事件,您必须这样做:
$(document).on('click', '.icon-ok-sign', function() {
alert('hey');
});
此方法提供了将委托事件处理程序附加到
页面的文档元素,它简化了事件处理程序的使用
将内容动态添加到页面时
这是因为您不能为将来的元素注册单击事件,您必须这样做:
$(document).on('click', '.icon-ok-sign', function() {
alert('hey');
});
此方法提供了将委托事件处理程序附加到
页面的文档元素,它简化了事件处理程序的使用
将内容动态添加到页面时
试试这个:
$(".icon-pencil").click(function() {
var pencil = $(this);
var row = $(this).parent('td').parent('tr');
row.find('td').not(":nth-last-child(2)").not(":last-child").each(function() {
$(this).html("hi");
});
pencil.removeAttr('class').addClass('icon-ok-sign');
});
// save item
$(".icon-ok-sign").click(function() {
alert("hey");
});
试试这个:
$(".icon-pencil").click(function() {
var pencil = $(this);
var row = $(this).parent('td').parent('tr');
row.find('td').not(":nth-last-child(2)").not(":last-child").each(function() {
$(this).html("hi");
});
pencil.removeAttr('class').addClass('icon-ok-sign');
});
// save item
$(".icon-ok-sign").click(function() {
alert("hey");
});
现在它调用了两次。您必须删除自己的单击调用:$(“.icon ok sign”)。单击(function(){alert(“hey”);});您刚刚复制了Stian的答案!我正在键入它,提交后,我看到了相同的结果answer@Mark我打了,但还是打了两次电话给twiceNow。你必须删除你自己的点击呼叫:$(“.icon ok sign”)。点击(函数(){alert(“hey”);});你刚刚抄了斯蒂安的答案!我正在打字,提交后,我看到了同样的答案answer@Mark我打了两次电话给twiceNow它打了两次我们需要更多的信息来确定它为什么被打了两次现在它被打了两次我们需要更多的信息来确定它为什么被打了两次。