jQuery的删除行点击不起作用? [英] jquery remove row on click not working?

查看:68
本文介绍了jQuery的删除行点击不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续明天的问题

function n() {
  $('.m').on('click',function() {
    var id = $(this).closest("tr").find(".t").text();
    var p= $(this).closest("tr").find(".t1").text();
    $('#c').append('<li class='li'>',id,<span class='c'>'"X"'</span>','</li>');
  });
} 
<style>
.c:hover
{
color:red;
}
.li
{
}
<script type="text/javascript">
$(document).on('click','.c',function()           
{

    $(this).closest("li").remove()
    alert("ok");
});

</script> 

在单击此"X"符号时,我要删除该列表,在警报中打印确定",但删除功能不起作用,为什么?

on clicking this 'X' symbol i want to delete that list,'OK' in alert printed but remove function not working why?

推荐答案

请确保在标记内添加适当的scriptstyle标记.它们也应适当关闭,例如style标记未关闭.未关闭的style标签可能会引起问题.

Be sure to add the appropriate script and style tags within the markup. They should also be closed appropriately, for example the style tag is unclosed. The unclosed style tag could be causing problems.

script中,也有单引号嵌套不正确的情况.在需要时(例如在标记中),使用外部单引号表示字符串文字,并在字符串文字内使用双引号.似乎您也正在尝试使用,进行串联,但是在Javascript中,串联运算符为+.

Also within the script there are single quotes that are nested incorrectly. Use outer single quotes to denote the string literal and double quotes within the string literal when required such as in markup. It also appears you are attempting to concatenate using , however in Javascript the concatenation operator is +.

<script> <!-- I didn't exist />
function n() {
  $('.m').on('click',function() {
    var id = $(this).closest("tr").find(".t").text();
    var p= $(this).closest("tr").find(".t1").text();

    //Concatenation and String literal fixed here
    $('#c').append('<li class="li">' + id + '<span class="c">X</span></li>');
  });
} 
</script>

<style>
    .c:hover
    {
        color:red;
    }

    .li
    {
    }
</style><!-- I wasn't closed -->

<script type="text/javascript">
$(document).on('click','.c',function()           
{

    $(this).closest("li").remove()
    alert("ok");
});

</script>

这篇关于jQuery的删除行点击不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆