js的一些使用。。。(最近项目jquery使用的总结)

一,点击按钮,替换html的一些信息

 <form action="" method="post">
<script type="text/javascript">
  function hello()
{
  document.getElementById('result').innerHTML = 'ok';
  return false;
}
</script>
<input type="submit" οnclick="return hello()"/>

</form>
<p id="result">呵呵</p>

结果: 先执行hello(); 依照hello()返回值如果为false,则停止

如果你的提交按钮用submit的话 return false是不能阻止表单提交的 要阻止表单提交 最好是button按钮 手动submit()

二:

2,table框里面点击一个元素,然后,执行删除操作,但是需要删除框隐藏层,而且从jsp里面的table的行列值都传给类,那么需要做事件绑定以及返回判断:

(1)html源码:

<table style="width:100%;" border="1" cellpadding="0" cellspacing="0" bordercolor="#999999" onClick="doit(event.srcElement)">。。。。。。</table>

(2)table取值:

<script language="javascript">
  function doit(arg)
  {
   if (arg.tagName == "TD")
   {
  // alert("你将要删除本会议");
    alert ('这是:'+(arg.parentElement.sectionRowIndex+1)+'行'+(arg.cellIndex+1)+'列!');
  
    //document.form1.action="/HlpAccessoryD?strOpt=Delete"; 
     meetingid=arg.cellIndex;
 
     RowIndex1=arg.parentElement.sectionRowIndex;
        alert("行:"+RowIndex1);
   //alert("meetingid"+meetingid);
   //绑定事件
   //$("p").live("click", function(){
    //$(this).after("<p>Another paragraph!</p>");
//});
    var sureflag = window.confirm("您确实要删除所选会议吗?");
       if(sureflag)
       {
        $("table").live("click",function(){
    // delete(){
    //document.deletemeeting.submit();
    document.getElementById("deletebutton").click();
    //alert("abc");
   // function delete(){
    //document.deletemeeting.action="bookcam/DeletePhotoG";
    //document.deletemeeting.submit();
    });
       }else
       {
        
       }
    //document.getElementById("deletebutton").live("click",function(){
   
   
    //$("#deleteshow").show();
   //function(){
 //  alert("#deleteshow");}
   
   //$("#deleteshow").show("slow",function(){
 //$("#deleteshow").boxy();
//});
   
   //$("p").show("fast",function(){
  // $(this).text("Animation Done!");
 //});
 $(function(){
 $(".boxy").boxy();
});
    //document.deletemeeting.meetingid=meetingid;
   //$("#deleteshow").fancybox();
   // document.deletemeeting.action="bookcam/DeletePhotoG";
    //document.deletemeeting.submit();
   //  document.meetinginfo.action="/bookcam/BookResultG"; document.meetinginfo.submit();
   ///
   }
  }

3,form表单(οnsubmit="return check()">关键点),隐藏域相当于克隆,想要进行判断,需要做事件处理;

<div id="deleteshow" style="display:none">
<div id="def"  style=" font-family: Monaco, Verdana, Sans-serif;font-size: 12px;background-color: #f9f9f9;border: 1px solid #D0D0D0;color: #666666;display: block;margin: 14px 0 14px 0;padding: 12px 10px 12px 10px;">

<script language="javascript">
function check(){
  
   var count = meetingid;
   var RowIndex=RowIndex1;
   alert("check的meetingid是:"+count)
   alert("上传上去的RowIndex是"+RowIndex)
      document.getElementById("meetingid").value=count;
        document.getElementById("RowIndex").value=RowIndex;
   return true;
  
  }
</script>
<form id="deletemeeting"  method="post" action="DeletePhotoG" οnsubmit="return check()">
 <div>
 <input style="display:none" id="RowIndex" name="RowIndex">
 <div style="display:none"><font size="2" style="display:none">日期:<%=day %></font></div>
 <div style="display:none"><input value="<%=day %>" id="date" name="date" size="50" type="text"></div>
 <input id="meetingid" name="meetingid" style="display:none">
 <input type="submit" name="Submit" id="deletebutton" value="删除会议" οnclick="delete(); ">
  <!--  <input type="button" id="mybutton" name="Submit" value="取消" οnclick="hide();">-->
 </div>
</form>
</div>
</div>

4,代码执行:首先是1,其次是2,在javascript里面点击按钮,然后执行返回判断方法,最终完成提交。在2里面可以进行判断操作。

<script language="javascript">
function check(){
  
   var count = meetingid;
   var RowIndex=RowIndex1;
   alert("check的meetingid是:"+count)
   alert("上传上去的RowIndex是"+RowIndex)
      document.getElementById("meetingid").value=count;
        document.getElementById("RowIndex").value=RowIndex;
   return true;
  
  }
</script>
5,fancybox弹窗很好看,但是在table里面需要不同的id的时候就麻烦了。。。明天奋斗这个!

三:

<script>
 function doAdd(){
  var ids=['1','2','3','4','5'];
  for (var i = 0; i<ids.length ;i++ )
  {
   document.getElementById("button"+ids[i]).onclick =
   function aaa(){
    alert(this.id.substring(this.id.length-1,this.id.length));
   };
  }
 }
</script>
</head>
<body>
<input type="button" value="B1" id="button1"/>
<input type="button" value="B2" id="button2"/>
<input type="button" value="B3" id="button3"/>
<input type="button" value="B4" id="button4"/>
<input type="button" value="B5" id="button5"/>
<br>
<br>
<input type="button" value="添加事件" οnclick="doAdd()"/>

四:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值