js事件对象的IsRevoked是什么 ios里面怎样监听js的事件
\u4e00\u4e2a\u5173\u4e8eJS\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u7684\u5f88\u57fa\u7840\u7684\u95ee\u9898\u770b\u6765\u662f\u4f60\u6ca1\u7406\u89e3\u6d4f\u89c8\u5668\u89e3\u6790html\u4ee3\u7801\u7684\u539f\u7406;
\u5176\u5b9e\u5f88\u7b80\u5355\u5c31\u662f\u4e00\u884c\u4e00\u884c\u89e3\u6790,\u6321\u78b0\u5230\u6807\u7b7e\u662f\u4e5f\u662f\u4e00\u884c\u4e00\u884c\u6267\u884c, \u524d3\u884c
function over(){document.form1.textarea.value+="onMouseOver\n";}
function out(){document.form1.textarea.value+="onMouseOut\n";}
function _click(){document.form1.textarea.value+="onclick\n";}
\u5176\u5b9e\u662f\u6ca1\u6709\u95ee\u9898\u7684, \u95ee\u9898\u5728\u4e8e\u7b2c4\u884c
var obj=document.getElementById("button_22");
\u8fd9\u884c\u8fd0\u884c\u4e4b\u540e obj\u662f\u7a7a\u7684, \u56e0\u4e3a \u6d4f\u89c8\u5668\u8fd8\u6ca1\u52a0\u8f7d\u89e3\u6790\u540e\u9762\u7684 html\u4ee3\u7801, \u4e5f\u5c31\u662f\u8bf4\u8fd0\u884c\u7b2c4\u884c\u4ee3\u7801\u65f6,\u6d4f\u89c8\u5668\u6ca1\u529e\u6cd5\u5728document\u627e\u5230button;
\u4fee\u6539\u5f88\u7b80\u5355; \u5c06script\u6807\u7b7e\u632a\u5230 \u7684\u540e\u9762;
\u65e0\u6807\u9898\u6587\u6863
#form1 h1 {
font-weight: 800;
}
#form1 p #textarea {
margin: 10px;
}
.a {
width: 600px;
}
.a #form1 #button_22 {
height: 70px;
width: 70px;
}
\u4e00\u4e2a\u4e8b\u4ef6\u6d4b\u8bd5\u9875
function over(){document.form1.textarea.value+="onMouseOver\n";}
function out(){document.form1.textarea.value+="onMouseOut\n";}
function _click(){document.form1.textarea.value+="onclick\n";}
var obj=document.getElementById("button_22");
obj.onmouseout=out;
obj.onmouseover=over;
obj.onclick=_click;
obj.value="the button is found"
\u5728iOS\u5f00\u53d1\u4e4bObjective-C\u4e0eJavaScript\u4ea4\u4e92\u64cd\u4f5c \u4e2d\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7stringByEvaluatingJavaScriptFromString \u53bb\u5b9e\u73b0\u5728obj-C\u4e2d\u83b7\u53d6\u5230\u76f8\u5173\u8282\u70b9\u5c5e\u6027\uff0c\u6dfb\u52a0javascript\u4ee3\u7801\u7b49\u529f\u80fd\u3002\u4f46\u662f\u6211\u4eec\u5982\u4f55\u76d1\u542c\u5230javascript\u7684\u54cd\u5e94\u4e8b\u4ef6\u5462\u3002\u5728MAC OS\u4e2d\u6709\u6548\u7684API\u53bb\u5b9e\u73b0\uff0c\u4f46iPhone\u6ca1\u6709\uff0c\u4f46\u6211\u4eec\u6709\u4e00\u4e2a\u6280\u5de7\u9014\u5f84\uff1a
\u5927\u6982\u601d\u8def\u662f\uff1a\u5728JavaScript\u4e8b\u4ef6\u54cd\u5e94\u65f6\uff0c\u901a\u8fc7\u8bbe\u7f6edocument.location\uff0c\u8fd9\u4f1a\u5f15\u53d1webview\u7684\u4e00\u4e2adelegate\u65b9\u6cd5\uff0c\u4ece\u800c\u5b9e\u73b0\u53d1\u9001\u901a\u77e5\u7684\u6548\u679c\uff0c\u5373\u8fbe\u5230\u76d1\u542c\u7684\u76ee\u7684\u3002
1\u3001\u5728javascript\u4e0ewebView\u4e4b\u95f4\u5b9a\u4e00\u4e2a\u534f\u8bae\u7ea6\u5b9a\uff1a
myapp:myfunction:myparam1:myparam2
2\u3001\u5728javascript\u4e2d\u6dfb\u52a0\u4ee3\u7801\uff1a
document.location = "myapp:" + "myfunction:" + param1 + ":" + param2;
3\u3001\u5728webView\u7684delegate\u65b9\u6cd5webView:shouldStartLoadWithRequest:navigationType: \u6dfb\u52a0
- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:@"myapp"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"myfunction"])
{
NSLog([components objectAtIndex:2]); // param1
NSLog([components objectAtIndex:3]); // param2
// Call your method in Objective-C method using the above...
}
return NO;
}
return YES; // Return YES to make sure regular navigation works as expected.
}
看来是你没理解浏览器解析html代码的原理;
其实很简单就是一行一行解析,挡碰到<script>标签是也是一行一行执行, 前3行
function over(){document.form1.textarea.value+="onMouseOver\n";}
function out(){document.form1.textarea.value+="onMouseOut\n";}
function _click(){document.form1.textarea.value+="onclick\n";}
其实是没有问题的, 问题在于第4行
var obj=document.getElementById("button_22");
这行运行之后 obj是空的, 因为 浏览器还没加载解析后面的 html代码, 也就是说运行第4行代码时,浏览器没办法在document找到button;
修改很简单; 将script标签挪到 </body>的后面;
扩展阅读:xbox series x ... js window document ... javascript document ... jstat gcutil ... oneplus 9r ... js事件循环event loop ... 国产任天堂switch手柄 ... switch 系列 ... js中对象上用tostring ...