我有一個圖像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]」 –