문제

How can one change the source of an image object in Dashcode (Javascript) at runtime?

I tried:

var image = document.getElementById("image").object; image.src = "IMG_0230.JPG";

도움이 되었습니까?

해결책

I have an image in a list view and I've set up a value transformer for that image that takes the name of the image file stored in the datasource and prepends a URL path to load the file from the server it resides on.

Is this similar to what you're trying to do? If so, then there is a section on Value Transformers in the DashCode doc. It's one of the few things that is documented! :)

다른 팁

I got this to work
I made sure that the image was stored in the Images folder of the project

var image = document.getElementById("image");
image.firstElementChild.src = "image source";

I'm not sure what the point of .object is, the reference should be enough. Is there an object property?

image.setSrc function is not working for me.

I found another way to solve the problem -

document.getElementById("imageView").innerHTML = '<img id="DC_img" 
    class="apple-hidden" apple-group="image" src="' + url + '">';

The Image Part of Dashcode creates a div block and inside it it creates img tag that contains source as attribute. So, either write the innerHTML for imageView or find the img tag with its ID and use setAttribute() function.

I always use this

var image = document.getElementById("imagetobeset");
image.firstElementChild.src = "imagefile";

Where imagetobeset is the name of the element you want to change and imagefile is the name of the file you want your image source to be set to.

Simply try this, it will work

document.getElementById("image").src="fineName.jpg";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top