- (void)webViewDidFinishLoad:(UIWebView *)webView {
[IDProgressHUD IDPlaceViewHideDirect:self.view]
//这里是js,主要目的实现对url的获取
static NSString * const jsGetImages =
@"function getImages(){\
var objs = document.getElementsByTagName(\"img\")\
var imgScr = ''\
for(var i=0i<objs.lengthi++){\
imgScr = imgScr + objs[i].src + '+'\
}\
return imgScr\
}"
[webView stringByEvaluatingJavaScriptFromString:jsGetImages]//注入js方法
NSString *urlResurlt = [webView stringByEvaluatingJavaScriptFromString:@"getImages()"]
mUrlArray = [NSMutableArray arrayWithArray:[urlResurlt componentsSeparatedByString:@"+"]]
if (mUrlArray.count >= 2) {
[mUrlArray removeLastObject]
}
//urlResurlt 就是获取到得所有图片的url的拼接;mUrlArray就是所有Url的数组
//添加图片可点击js
[mWebView stringByEvaluatingJavaScriptFromString:@"function registerImageClickAction(){\
var imgs=document.getElementsByTagName('img')\
var length=imgs.length\
for(var i=0i<lengthi++){\
img=imgs[i]\
img.onclick=function(){\
window.location.href='image-preview:'+this.src}\
}\
}"]
[mWebView stringByEvaluatingJavaScriptFromString:@"registerImageClickAction()"]
}
//在这个方法中捕获到图片的点击事件和被点击图片的url
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//预览图片
if ([request.URL.scheme isEqualToString:@"image-preview"]) {
NSString* path = [request.URL.absoluteString substringFromIndex:[@"image-preview:" length]]
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
//path 就是被点击图片的url
return NO
}
return YES
}
用jquery做的话,代码如下:<title></title>
<script src="../js/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".logo").mouseenter(function () {
$(".logo_pass").css("display", "block")
}).mouseout(function () {
$(".logo_pass").css("display", "none")
})
})
</script>
</head>
<body>
<div class="logo">111</div>
<div class="logo_pass" style="display:none">222</div>
</body>
</html>
js的话:
给div设置id比较好做
<script type="text/javascript">
window.onload = function () {
var logo = document.getElementById("logo")
logo.onmouseover = function () {
document.getElementById("logo_pass").setAttribute("style", "display:block")
}
logo.onmouseout = function () {
document.getElementById("logo_pass").setAttribute("style", "display:none")
}
}
</script>
</head>
<body>
<div id="logo">111</div>
<div id="logo_pass" style="display:none">222</div>
</body>