0

我很难弄清楚这会是什么:

<img src="/path/frontend/bigpath/default/images/heyhey/coolguy/' + partElements['awesometimes']['color'] + '.png">

该图像的 URL 输出是什么?


它与此页面有关;自行车定制器。

我喜欢这个网站,并试图更好地了解他们是如何在 JS 中实现这一点的。

http://www.myownbike.de/

4

1 回答 1

3

Your question is unclear. As the value that it gets evaluated is purely dependent on

partElements['awesometimes']['color'] ( I assume partElements is JavaScript array )

Also, it would result in syntax error as the concatenation done is incorrect. Moreover, the concatenation should be done part of JavaScript. Your HTML code cannot do it. If you are trying to do it in HTML, it will never work.

Below code might help you out.

<script type="text/JavaScript">
window.onload=function(){
    document.getElementById('myImg').src = "james" + "bond" + ".jpg";
}
</script>
<img src="" id="myImg">

Let the JavaScript do its concatenating business. Let HTML do its rendering business.

If you are finding tough time in what that gets evaluated to, start using debugging tools. All the major browsers provide these features.

Chrome debugging tools are good. References : https://developers.google.com/chrome-developer-tools/docs/javascript-debugging

Try evaluating the string concatenation of img src in chrome console to get to know it.

于 2013-10-15T03:56:24.030 回答