[英]How can we change the size of images in HTML by tag name?
I'm building an article reading iOS app.Article contains multiple images. 我正在编写一篇阅读iOS应用的文章。该文章包含多个图像。
I am unable to change the size of images in html. 我无法更改html中图像的大小。
here is my code:- 这是我的代码:-
NSString *url=[[NSString alloc] initWithString:_DetailModal1[3] ];//contain html content.<br>
NSString *javaScriptStar=@"<script>a = document.getElementsByTagName('img');for (i = 0;i a.length;i++) {a[i].style.maxWidth = '600px';}</script><div style = \"line-height:85px;font-size:55px;font-family: Helvetica, Arial, Sans-Serif;font-weight:400;\">";
Please use the width
property instead of maxWidth
. 请使用
width
属性而不是maxWidth
。 Also your for loop is missing <
. 另外,您的for循环缺少
<
。
Please check this JSFiddle link 请检查此JSFiddle链接
Here is the updated working code 这是更新的工作代码
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<img border="0" src="http://t0.gstatic.com/images?q=tbn:ANd9GcS28hGdxjiRyMSuYNKY3ogoqKSZUZFRqlH93apAmZlJ-chii5EG"
alt="Pulpit rock" width="304" height="228"/>
<script>
function myFunction() {
var a = document.getElementsByTagName('img');
var i =0;
for (i = 0;i< a.length;i++)
{
a[i].style.width = '1000px';
}
}
</script>
</body>
</html>
NSString *url=[[NSString alloc] initWithString:_DetailModal1[3] ];//contain html content.
NSString *javaScriptStar=@"<style type=\"text/css\">img { width : 1000px !important; height:500px !important;}</style>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.