Jquery在iframe和图像之间切换

时间:2017-08-18 21:26:06

标签: jquery

我希望有一个onclick按钮在iframe和图像之间切换。

这怎么可能?如果可能的话,请用jsfiddle告诉我。

1 个答案:

答案 0 :(得分:0)

$('iframe').toggle();
$('button').click(function(){
  $('img').toggle();
  $('iframe').toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>toggle</button>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2AAAAIcCAIAAAAfZ1r9AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABzqSURBVHhe7d0tlOJKAoDRlkgkEolEIpFIJBKJROKQSCQSiUQikUgkEolEIndrp+qxXfPmh3RDNwn3qqZCMmNyzndCqurtPwAA8I5ABAAgIxABAMgIRAAAMgIRAICMQAQAICMQAQDICEQAADICEQCAjEAEACAjEAEAyAhEAAAyAhEAgIxABAAgIxABAMgIRAAAMgIRAICMQAQAICMQAQDICEQAADICEQCAjEAEACAjEAEAyAhEAAAyAhEAgIxABAAgIxABAMgIRAAAMgIRAICMQAQAICMQAQDICEQAADICEQCAjEAEACAjEAEAyAhEAAAyAhEAgIxABAAgIxABAMgIRAAAMgIRAICMQAQAICMQn9pqtep2u8vlMn0GAHg8gfi8xuPx2w+1Wi0NAQA8nkB8RufzudfrxToM+v1+OgAA8HgC8ekcj8dWq5Xa8EcdXi6XdAwA4PEE4nPZbrf1ej214dvbZDJJBwAAvopAfCLL5bJWq8U0DH+sVqt0AADgCwnEZ7Hb7a512Gg0wsd0AADgawnEp3A+n5vNZqzDVqt1PB7TAQCALycQn0K/3491WKvVDodDGgUA+A4C8fvN5/NYh4E1sQGAbycQv9n7Vw+Hw2EaBQD4PgLxO/306qH1DgGAZyAQv5NXDwGAJyQQv41XDwGA5yQQv8fhcPDqIQDwnATiN7hcLu12O9ahVw8BgGcjEL/BdDqNdVir1fb7fRoFAHgOAvGr7Xa7WIf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