如何隐藏动态添加的图像 [英] how to hide image that is added dynamically

查看:91
本文介绍了如何隐藏动态添加的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助我!

首先,对不起,如果我问无意义问题。我是jquery的新手。我创建了一个画布,我想绘制图像,当我点击按钮图像时应该隐藏。我写了这段代码。



 <   script     src   =  / js / jquery2.0.js >  <   /   script  >  

< body >
< canvas id = cnv style =< /跨度> <温泉n class =code-keyword> border-style:double; width < span class =code-keyword> = 500 高度 = 500 class = cls > < / canvas >
< 按钮 id = btn > 点击< / button >
< / body >





这是javascript



  function  test() 
{

var id = STR1;
can = document .getElementById( cnv );
ctx = can.getContext( 2d);

img.src = / images / rope.png;
img.id = id;
img.onload = function ()
{
ctx.drawImage(img, 0 0 );
$( this )。attr( id,id);
}
}

function clicked()
{
$( #str1)。hide( 5000 );
}







帮助我。

解决方案

this )。attr( id,id);
}
}

function clicked()
{


< blockquote>( #str1)。hide( 5000 );
}







帮助我。


< blockquote>你没有使用jQuery的强大功能。例如,不需要 document.getElementById ,因为jQuery ID选择器执行它。至于你的问题:你不能在代码中的任何地方使用点击,那么你的期望是什么?



尝试遵循jQuery代码的一般模式,使用


Help me!
First, sorry if I ask non-sense question. i am new to jquery. I created one canvas, in that i want to draw image, and when I click on the button image should be hidden. and I written this code.

<script src="/js/jquery2.0.js"></script>

<body>
    <canvas id="cnv" style="border-style:double;" width="500" height="500" class="cls"></canvas>
    <button id="btn">Click</button>
</body>



This is javascript

function test()
{

        var id="str1";
        can = document.getElementById("cnv");
        ctx = can.getContext("2d");
        
        img.src = "/images/rope.png";
        img.id = id;
        img.onload = function ()
        {
            ctx.drawImage(img, 0, 0);
            $(this).attr("id", id);
        }       
    }

    function clicked()
    {
        $("#str1").hide(5000);
    }




Help me with this.

解决方案

(this).attr("id", id); } } function clicked() {


("#str1").hide(5000); }




Help me with this.


You are not using the power of jQuery. For example, document.getElementById is not needed, because the jQuery ID selector does it. As to your question: you don''t use clicked anywhere in code, so what do your expect?

Try to follow the general pattern of jQuery code, use


这篇关于如何隐藏动态添加的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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