[英]Set image width and height with jquery
I upload an image with the ck editor. 我使用ck编辑器上传图像。 When i select and upload the file, the editor automatic write the image width and height. 当我选择并上传文件时,编辑器会自动写出图像的宽度和高度。
If i dont write in to this two field manualy 100% and 100%, how can i edit this with jquery? 如果我没有手动将这两个字段写入100%和100%,该如何使用jquery进行编辑? With this code, it writes the width and height to 100%, but the ck editor add these features into style attr. 使用此代码,它将宽度和高度写入100%,但是ck编辑器将这些功能添加到样式attr中。
$('div.content img').attr('width', '100%');
$('div.content img').attr('height', '100%');
How can i modify the img-s style attr with jquery, and set width and height to 100%? 如何使用jquery修改img-s样式属性并将宽度和高度设置为100%?
Thank you! 谢谢!
You can just use jQuery
's CSS - 您可以只使用jQuery
的CSS-
$('div.content img').css({
'width' : '100%',
'height' : '100%'
});
If you need to set the style attributes, you can use jQuery's .css(): 如果需要设置样式属性,则可以使用jQuery的.css():
$('div.content img').css('width', '100%');
$('div.content img').css('height', '100%');
See https://api.jquery.com/css/ 参见https://api.jquery.com/css/
Have you tried something like this: 您是否尝试过以下方法:
$("div.content img").css("cssText", "width: 100% !important;");>
Using jQuery to create the css and using !important to force it to take change 使用jQuery创建CSS并使用!important强制其进行更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.