我有一个图像draggable
并希望通过PHP保存它,所以我决定获取内部样式并将其作为输入字段的值,所以我可以通过$_POST
得到它,但我是无法找到一样,如果它是一个内部HTML
数据我可以通过调用innerHTML
语法得到它,但像这样有越来越样式图像的任何方式使用javascript获取css样式属性
<div class="scott_img">
<img id="uploadPreview" src="<?php echo (empty($data['profile_pic'])) ? "images/profile.jpg" : "uploads/" . $data['profile_pic']; ?>" style="style goes here">
<span class="scouttag"></span>
</div>
<form method="POST" action="profile.php?uid=<?php echo $uid; ?>" enctype="multipart/form-data" style="text-align:center;">
<input id="uploadImage" type="file" name="image" style="margin:auto;" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="hidden" id="uploadPreview1" value="need style here so i can save it to database" />
<button type="submit" name="update_picture" class="btn_form">Update Picture</button>
</form>
<img class="scott_line"src="images/line.png">
<script>
(function() {
var elem = document.getElementById('uploadPreview');
var val = getComputedStyle(elem);
document.getElementById('uploadPreview1').value = val;
var $section = $('.scott_img').first();
$section.find('#uploadPreview').panzoom({
$zoomRange: $section.find(".zoom-range"),
$reset: $section.find(".reset")
});
})();
</script>
谢谢
getComputedStyle(elem)'返回什么? –
value =“[object CSSStyleDeclaration]” –