简体   繁体   English

UIWebView Javascript onclick 事件未将事件对象发送到函数

[英]UIWebView Javascript onclick event not sending event object to function

I am dynamically inserting HTML using simple NSStrings and then loading that into a UIWebview, I am doing this:我使用简单的 NSStrings 动态插入 HTML,然后将其加载到 UIWebview 中,我这样做:

[NSString stringWithFormat:@"<div onclick=\"MyClickEvent(e);\"....some more text here">

and have a function defined like this:并有一个这样定义的函数:

function MyClickEvent(e)
{
    //Some other code here
    e.stopPropagation();
    return false;
}

The function is never getting called, because of the way the parameter is being passed as e, if I use quotations like this:该函数永远不会被调用,因为参数作为 e 传递的方式,如果我使用这样的引号:

[NSString stringWithFormat:@"<div onclick=\"MyClickEvent('e');\"....some more text here">

Then the function will be called but e is just a simple string as expected, how can I correctly pass the event object?然后该函数将被调用,但 e 只是一个简单的字符串,我该如何正确传递事件对象?

The HTML at the end simply looks like this:最后的 HTML 看起来像这样:

<div onclick="MyClickEvent(e);">

which I believe is how it should be, but somehow the event object is not being sent, what am I doing wrong?.我相信这是应该的,但不知何故没有发送事件对象,我做错了什么?。

I got it to work, apparently what you need to do is this:我让它工作了,显然你需要做的是:

[NSString stringWithFormat:@"<div onclick=\"MyClickEvent(event);\"....some more text here">

So simply naming the parameter event, does the trick.所以简单地命名参数事件,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM