使用JQuery更改iframe上的图像

时间:2022-09-04 21:21:27

I need to change an image with jQuery when I click on image of my webpage I need that the page show me a prompt, alert... or similar where I put the new path of the new image.

当我点击我的网页图片时,我需要用jQuery更改图像我需要页面向我显示提示,警告......或类似我放置新图像的新路径。

Anyone have any idea?

任何人都有任何想法?

I show my code where I change paragraphs and headers with Jquery, I need similar but for images.

我展示了我用Jquery更改段落和标题的代码,我需要类似的但是对于图像。

$("#probando").contents().find("#cabecera1").click(function () {
    var nuevoTexto = prompt("Introduzca el nuevo contenido");
    $("#probando").contents().find("#cabecera1").text(nuevoTexto);
});

The image that needs changed is in an frame.

需要更改的图像位于框架中。

<iframe id="probando" src="prueba2.html" scrolling="auto" height="700" width="750" marginheight="0" marginwidth="0" name="probando"></iframe>

2 个解决方案

#1


Something I don't understand : You have to click on an image which is in a frame, and when you do, a prompt appears to write a new path for the image. When the prompts submitted, the image changes of src, is that it ?

我不明白的东西:你必须点击一个框架中的图像,当你这样做时,会出现一个提示,为图像写一个新的路径。当提示提交时,src的图像变化,是吗?

In that case, you can directly write the code on the frame's included page.

在这种情况下,您可以直接在框架的包含页面上编写代码。

$().ready(function() {
  $('#imageId').click(function() {
    var newPath = prompt('Please enter new path for image :');
    $(this).attr('src',newPath);
  });
});

If it's not the case, please explain what's the structure and what is where =)

如果不是这样,请解释结构是什么,以及在哪里=)

#2


<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <title>iframehide</title>
    <script type="text/javascript">
        $(function() {
            var f = $('#foo')
            f.load(function() {
                f.contents().find('div').hide();
            })
        })
    </script>
</head>

<body>
    <iframe id="foo" src="iframehide-frame.html" /></iframe>
</body>
</html>

#1


Something I don't understand : You have to click on an image which is in a frame, and when you do, a prompt appears to write a new path for the image. When the prompts submitted, the image changes of src, is that it ?

我不明白的东西:你必须点击一个框架中的图像,当你这样做时,会出现一个提示,为图像写一个新的路径。当提示提交时,src的图像变化,是吗?

In that case, you can directly write the code on the frame's included page.

在这种情况下,您可以直接在框架的包含页面上编写代码。

$().ready(function() {
  $('#imageId').click(function() {
    var newPath = prompt('Please enter new path for image :');
    $(this).attr('src',newPath);
  });
});

If it's not the case, please explain what's the structure and what is where =)

如果不是这样,请解释结构是什么,以及在哪里=)

#2


<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <title>iframehide</title>
    <script type="text/javascript">
        $(function() {
            var f = $('#foo')
            f.load(function() {
                f.contents().find('div').hide();
            })
        })
    </script>
</head>

<body>
    <iframe id="foo" src="iframehide-frame.html" /></iframe>
</body>
</html>