我有一个简单的 java 脚本文件。下面是我的示例 js 代码
功能自动播放(videoId,st,en){ player.loadVideoById({ 'videoId': videoId, 'startSeconds': st, 'endSeconds': en, 'suggestedQuality': 'small' }); 播放器.playVideo();
function getState(){
alert(player.getPlayerState());
return player.getPlayerState();
}
function CallTweak()
{
alert(player.getPlayerState());
document.getElementById("mytext").innerHTML = player.getPlayerState();
var data=player.getPlayerState();
AndroidFunction.showToast(data);
alert('second alert');
}
我调用一个函数它工作正常,但我试图调用两个函数,例如 autoplay() 和 CallTweak(),这些方法没有被调用。 下面是调用函数的示例代码
web_view.loadUrl("javascript:CallTweak()"); web_view.loadUrl("javascript:autoplay()");
如何在 android 中单击一次按钮一次调用多个函数?提前致谢。
最佳答案
采取两种方法之一
或者,在你的 javascript 代码中,定义第三个函数来调用另外两个
function callBothFunctions(){
CallTweak();
autoplay();
}
然后调用第三个函数
web_view.loadUrl("javascript:callBothFunctions()");
或者,另一种方法是使用匿名自执行函数,如
string javascriptFunctionCall =
"javascript:"
+ "(function(){"
+ "CallTweak();"
+ "autoplay();"
+"})()";
web_view.loadUrl(javascriptFunctionCall);
关于javascript - 如何在android中一次调用多个javascript函数来加载webview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34414007/