[英]How can we change the size of images in HTML by tag name?
我正在編寫一篇閱讀iOS應用的文章。該文章包含多個圖像。
我無法更改html中圖像的大小。
這是我的代碼:-
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;\">";
請使用width
屬性而不是maxWidth
。 另外,您的for循環缺少<
。
請檢查此JSFiddle鏈接
這是更新的工作代碼
<!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.