javascript(一 多级条件 确认用户选择 转移导航菜单)

1.确认用户的选择:

比如在用户删除之前弹出窗体再次确认是否删除 如果是进入另一个jsp界面 如果不是则不动

js代码:

<script type="text/javascript">
       function confirmAct() {
           if(confirm("确认删除文章?")){
               return true;
           }
           else{
               return false;
           }
       }
    </script>

html代码:

<a href="test.jsp" οnclick="return confirmAct();">执行操作</a>

2.使用多级条件

按每个按钮弹出相应的值

当加载页面时调用init()函数

js代码:

<script type="text/javascript">
        window.οnlοad=init;
        function init() {
            document.getElementById("lincoln").οnclick=saysome;
            document.getElementById("kenndey").οnclick=saysome;
            document.getElementById("nixon").οnclick=saysome;
        }
        function saysome() {
            switch (this.id){
                case "lincoln":
                    alert("lincoln");
                    break;
                case "kenndey":
                    alert("kenndey");
                    break;
                case "nixon":
                    alert("nixon");
                    break;
            }
        }
    </script>

html代码:

 <form action="#">
          <input type="button" id="lincoln" value="lincoln"/>
          <input type="button" id="kenndey" value="kenndey"/>
          <input type="button" id="nixon" value="nixon"/>
      </form>

3.选择并转移导航菜单

通过菜单进入不同大的目的地,不需要Go按钮

js代码

window.onload = initAll;
        function initAll(){
            //属性值设为0,显示select a topic
            document.getElementById("newLoc").selectedIndex = 0;
            //脚本在菜单选择发生改变时,调用change函数
            document.getElementById("newLoc").onchange = change;
        }
        function change(){
            //newLoc变量查找访问者在菜单中选择的值
            var newLoc = document.getElementById("newLoc");
            //得到值之后获得对应菜单项的值,即希望跳转网页的名称,赋值给newPage
            var newPage = newLoc.options[newLoc.selectedIndex].value;
            if(newPage != ""){
                //如果值不为空跳转到指定的url
                window.location = newPage;
            }
        }

html代码:

nosript不支持javascript浏览器会出现按钮

<form action="#">
      <select id="newLoc">
       <option selected>Select a topic</option>
       <option value="s1.html">Cross-checking fields</option>
       <option value="test.jsp">Working with radio buttons</option>
     </select>
   <noscript>
     <input type="submit" value="Go There!">
   </noscript>
 </form>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值