点击图片时移除标签? [英] Remove label when image is clicked?

查看:63
本文介绍了点击图片时移除标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTML。我添加了以下标签和图片:

I am using HTML. I have added a label and image as below:

点击红十字标记需要删除相应的标签。我如何做到这一点?

on click of red cross mark the corresponding label needs to be removed. How can I do this?

我在代码下面但是不工作。

I have below the code but it is not working.

$("#lbRemove").click(function(){
    $(this).parent().parent().remove();
});



<section class="col2">        
        <div class="lbYourSelectedTarget">
            <span style="color: rgb(0, 0, 0); font-size: 100%;">Your selected businesses:</span>
            <div class="lbSelectedCriteriaTarget" style="border: 1px solid; height: 250px; overflow:scroll;">
                <ul class="lbCriteriaContainer">

                </ul>
            </div>
        </div>
        <br/><br/><br/><br/><br/><a class="button right" href="index2.html">Continue</a>
      </section>



$(function(){
    $("select").multiselect();

    $("select").change(function () {    
        //console.log('asas: '+$(this).val());
        var str = $(this).val();
        /*var ff = "option1,option2";
        console.log(ff.split(",")[1]);      
        alert(str.length);*/
        if(str && str.length > 1){
            var last_element = str.pop();           
            $('.lbCriteriaContainer').append("<li id='"+ last_element +"' class='lbAlt'><a id='lbRemove' class='lbRemoveCriteria'><img src='images/cross.jpg' id='lbRemove' width='15' style='padding-top: 3px; cursor:hand ; cursor :pointer;' /></a><span> "+ last_element +"</span></li>");
            str = "";
        }else if (str && str.length == 1){
            $('.lbCriteriaContainer').append("<li id='"+ str +"' class='lbAlt'><a id='lbRemove' class='lbRemoveCriteria'><img src='images/cross.jpg' id='lbRemove' width='15' style='padding-top: 3px; cursor:hand ; cursor :pointer;' /></a><span> "+ str +"</span></li>");
            str = "";
        }
    }).change();

    $("#lbRemove").click(function(){
        $(this).parent().parent().remove();
    });
});


推荐答案

看起来你使用相同

Seems that you use same id for multiple HTML elements.

用一个类替换它,所以在HTML边你会有 class = lbRemove(而不是 id =lbRemove)和jQuery:

Replace it with a class. So in HTML side you will have class="lbRemove" (instead of id="lbRemove") and in jQuery:

$(".lbRemove").click(function(){
    $(this).parent().parent().remove();
});

查看 id 之间的区别


  • id = name [CS] / code>

  • id = name [CS]


此属性为元素分配名称,此名称必须是唯一的


  • class = cdata-list [CS]


    此属性为元素分配一个类名或一组类名。 任何数量的元素可以分配相同的类名称。多个类名必须用空格字符分隔。

    This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.


  • 这篇关于点击图片时移除标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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