我用 Javascript 添加了一张图片到网页,但我不知道如何修改或放置它。我如何将 CSS 链接到图像,或者我可以在没有 CSS 的情况下修改它?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PingPongKép</title>
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<script>
function ilonaKep() {
var img = new Image();
img.src = 'img/ilona.jpg';
document.body.appendChild(img);
}
</script>
<p>Let's See the image
<script>
ilonaKep();
</script>
</p>
</body>
</html>
最佳答案
JQuery 使这变得非常简单。在图像的 style
quotes 中应用您想要的任何样式
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<p> Lets see the image: </p>
<script>
window.onload = function(){
addImage();
function addImage() {
$('body').append('<img style="any css styling in here" src="img/ilona.jpg">');
}
}
</script>
</body>
</html>
关于javascript - 如何将 CSS 参数链接到 javascript img?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46623027/