While resizing the picture, I want the picture width added to < div id="w" >< /div >, I have tried the following, anyone can help? thank you:
<script>
$(document).ready(
function() {
$( "#resizable" ).resizable({
resize: select_function
});
});
var select_function = function(event, ui)
{
$("#w").text($( "#resizable" ).attr("width"));
};
</script>
<div id="w">Test</div>
<img border="0" id="resizable" src="picture.png">
You don't have a width=""
attribute.
To get the actual width of the element, call $( "#resizable" ).width()
.
你试过像这样得到图像的宽度吗?
$("#w").html($( "#resizable" ).width());
You either need to add a width
attribute to the img
tag.
<img border="0" id="resizable" src="picture.png" width="500px">
Or you need to use the built-in JQuery width()
function.
$( "#resizable" ).width();
I recommend checking out the JQuery docs on .width() and .attr() to get a better understanding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.