开发者

Issue with targeting objects using stringByEvaluatingJavaScriptFromString

I have a JQuery Carousel controlled by two images (a right image and a left image). The carousel script itself handles an event on the images to rotate the carousel upon clicking.

The client recently asked me to port the website over to an App, cheaply. Therefore I used a UIWebView which just loads the website.

I have added several extensions to it to smarten it up and to make it more suitable for app display. One of these extensions is the addition of a swipe gesture to control the carousel.

At the moment, this is my script:

- (void) handleSwipeGesture:(UISwipeGestureRecognizer*)swipe{
    NSString *scriptInject;
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
        scriptInject = @"alert('Right');$('#right-but').click();";
    } else if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
        scriptInject = @"alert('Left');$('#left-but').click();";
    }
    [webView stringByEvaluatingJavaScriptFromString:scriptInject];
}

This handles my two gestures. What I want to happen is that a right swipe just triggers the right button to shift the carousel, I'm getting the alert('Right') but not getting the effect of the click. Would 开发者_开发百科this be JQuery? Can you add JQuery into stringByEvaluatingJavaScriptFromString?

I've tried $('#right-but').trigger('click');

Here's my HTML for those buttons:

<div id="nav">
    <a id="right-but"><img src="img/navbtn.png" align="left" style="z-index:94"/></a>
    <a id="left-but"><img src="img/navbtn.png" align="right" style="z-index:94"/></a>
</div>


I looked into the Carousel Jquery File and found that to control the button clicks, there is a mouseup event bound to the object as opposed to a click event.

$('#right-but').trigger('mouseup');

Fixed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜