下拉选项,然后弹出警报 [英] dropdown options and then alert pop up

查看:62
本文介绍了下拉选项,然后弹出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建任何种类的下拉列表并显示警报以显示所选值
JavaScript和链接部分到文件

creating any kind of drop-down list and alert show the selected value
The JavaScript and linking part to the file

推荐答案

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script>
<pre lang="cs">var myform = document.getElementById("someform")
for (var i = 0; i < myform.elements.length; i++) 

    if (myform.elements[i].type == "select-one" || myform.elements[i].type == "select-multiple") {

        myform.elements[i].className = "selectclass"

    }

}

    &lt;title&gt;Dropdown Alert&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;HTMLPage.htm&quot;&gt;



&lt;h1&gt;Choose one option at a time&lt;/h1&gt;

&lt;select id=&quot;sample&quot; onchange=&quot;alertselected(this)&quot;&gt;

    &lt;option value=&quot;val0&quot;&gt;GMAIL&lt;/option&gt;

    &lt;option value=&quot;val1&quot;&gt;TWITTER&lt;/option&gt;

    &lt;option value=&quot;val2&quot;&gt;FACEBOOK&lt;/option&gt;

    &lt;option value=&quot;val3&quot;&gt;INSTAGRAM&lt;/option&gt;

    &lt;option value=&quot;val4&quot;&gt;FLIXTER&lt;/option&gt;

&lt;/select&gt;

&lt;input type=&quot;button&quot; onclick=&quot;alertselected(document.getElementById())&quot; value=&quot;alert&quot; /&gt;

&lt;/form&gt;



&lt;/body&gt;

&lt;/html&gt;</pre>


,但不是所需的紧凑型解决方案.
想通了,但是使用了此功能.
but not the desired compact solution.
figured out though,, used this function.


这篇关于下拉选项,然后弹出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆