[英]Detect click on HTML option tag through javascript in Android WebView
I have a form in a webview. 我在webview中有一个表单。 I'm able to detect button clicks and perform required tasks.But in the form, there is a option tag. 我能够检测到单击按钮并执行所需的任务。但是在表单中,有一个选项标签。 Based on the selected item type, I should perform next task. 根据所选的项目类型,我应该执行下一个任务。 But I'm unable to detect the option click event. 但是我无法检测到选项单击事件。 I tried both with onClick and onChange. 我尝试了onClick和onChange。 Both doesn't work. 两者都不起作用。 Any idea how to detect its click event? 知道如何检测其点击事件吗?
I tried the below code in my html code: 我在html代码中尝试了以下代码:
<div class="label"><b>Type :</b></div>
<div class="field">
<select name="type" >
<option value="video" selected="selected" onchange="videos.performClick()">video</option>
<option value="image" onchange="images.performClick()">image</option>
</select>
</div>
</div>
You need to listen for onchange
event on select field. 您需要在选择字段上监听onchange
事件。
<div class="label"><b>Type :</b></div>
<div class="field">
<select name="type" onchange="onSelectFieldChange(this)">
<option value="video" selected="selected">video</option>
<option value="image">image</option>
</select>
</div>
</div>
Now you write onSelectFieldChange
function which handles redirection based on the selected option. 现在,您编写onSelectFieldChange
函数,该函数根据所选选项处理重定向。
function onSelectFieldChange(element) {
switch(element.value) {
case 'video':
videos.performClick()
break;
case 'image':
images.performClick()
break;
default:
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.