0
我想将图像的src
设置为函数调用的返回值。以下是我现在做:如何通过函数调用设置图像的src?
<img src="get_src()" alt="can't display picture" />
和脚本是:
function get_picA() {
return "picA.png";
}
但它不工作。
我想将图像的src
设置为函数调用的返回值。以下是我现在做:如何通过函数调用设置图像的src?
<img src="get_src()" alt="can't display picture" />
和脚本是:
function get_picA() {
return "picA.png";
}
但它不工作。
你不能这样设置它。
您可以用JavaScript更改值:
<img id="image" src="picB.png" alt="can't display picture" />
document.getElementById("image").setAttribute("src","picA.png");
你不能这样做的。 src
属性不解释JavaScript。
你可以做这样的:
<img id="picA">
<script type="text/javascript">
function get_picAPath(){
return "picA.png";
}
document.onload = function(){
document.getElementById('picA').src= get_picAPath();
};
</script>