2015-04-08 116 views
0

我在webview中有一个表单。我能够检测到按钮点击并执行所需的任务。但在表单中,有一个选项标签。根据选择的项目类型,我应该执行下一个任务。但我无法检测到选项点击事件。我尝试了onClick和onChange。两者都不起作用。任何想法如何检测其点击事件?通过Android WebView中的javascript检测点击HTML选项标记

我尝试下面的代码在我的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> 

回答

1

你要听上选择字段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> 

现在你写了onSelectFieldChange函数,它根据选定的选项处理重定向。

function onSelectFieldChange(element) { 

     switch(element.value) { 
     case 'video': 
      videos.performClick() 
      break; 
     case 'image': 
      images.performClick() 
      break; 
     default: 
      break; 
     } 

    } 
+0

嗨..谢谢,生病试试这个,回到你身边。 –

+0

嗨,我试着按你的建议。但我没有得到回调.. –

+0

嗨,谢谢..它为我工作..我犯了一个小错误.. –