<div id="companyLogo"></div>
<script type = "text/javascript">
var imageName = prompt("Client Logo Image:");
$('#companyLogo').html(<img src = imageName, style="-webkit-filter: invert(100%);">);
</script>
我正在尝试将imageName作为“img src”标记的来源。任何帮助是极大的赞赏。谢谢!
答案 0 :(得分:1)
将javascript远离html是一种更好的做法。所以你可以像这样创建一个html文档:
<!DOCTYPE html>
<html>
<body>
<img id="companyLogo" src="path/to/some/default.img" alt="Your Company Logo" />
<script>
//prompts user for input
var imgSrc = prompt("Please input name");
//changes src of the targeted image to the value input by the user
document.getElementById("companyLogo").src = imgSrc;
</script>
</body>
</html>
这是fiddle
答案 1 :(得分:1)
试试这个。
在开始时:
<div id="companyLogo">
<img src="" id="#companyImg" style="display:none;" />
</div>
在某些情况下,会向用户显示提示框
<script>
$(document).ready(function(){
var imageName = prompt("Client Logo Image:");
$("#companyImg").attr('src', 'your image path' + imageName);
$("#companyImg").css('display','block');
});
</script>