jQuery if语句并删除iframe [英] jquery if statement and remove iframe

查看:196
本文介绍了jQuery if语句并删除iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jquery中编写if语句:

How do i write an if statement in jquery:

如果用户单击图像div#ProductImages > img然后隐藏/删除iframe,则为

?

IF the user clicks on an image div#ProductImages > img then hide/remove the iframe?

这就是我所拥有的: (我的代码会将youtube视频附加到页面上的div位置)

This is what i have: (my code will append the youtube video to a div location on the page)

一旦用户再次点击图片,我需要移除iframe.

I need to remove the iframe once the user starts clicking on the images again.

var $video=$('div.icon iframe');
var $productImage=$('.product-image');
var $icon=$('.icon');
$icon.on('click',function()
{
    $('.product-image').append($video);
});

对不起,我的意思是删除 http://jsfiddle.net/t7qMF/1/

推荐答案

隐藏:

$('#my-iframe').hide();

要删除:

$('#my-iframe').remove();

从您的示例中尚不清楚,您试图将逻辑放置在何处.

It is not clear from your example what logic you're trying to place where.

但是您将需要某种点击侦听器.

But you would need some kind of click listener.

$('#my-image').click(function() {
    // hide or remove iframe
});

这篇关于jQuery if语句并删除iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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