我想更改圖像元素的src,爲此我使用此代碼,但當單擊「添加」按鈕時它不起作用,請幫助.... 。如何通過javascript更改src圖像元素
<html>
<head>
<meta charset="UTF-8">
<title>Edit Home Page</title>
<script type='text/javascript'>
function setimgsrc()
{
$('#image').attr("src",document.getElementById("src").val());
};
</script>
</head>
<body>
<div class='center-block'>
<label >course title: </label>
<input type="text" id="title" name="title" placeholder="enter title for this course" >
<br> <label >course description: </label>
<input type="text" id="des" name="des" placeholder="enter decription for this course" >
<br> <label >image source : </label>
<input type='text' id='src' name='src' >
<input type='button' class='btn' onclick='setimgsrc()' value='add'> <br> <img id='image' style='width:500px; height:500px' > </div>
</body>
</html>
什麼「*不起作用*」關於它? – Marcus