首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

如何把JS函数写到onclick里面

2013-01-18 
怎么把JS函数写到onclick里面本帖最后由 menqi22 于 2013-01-12 14:59:14 编辑// ----- popup_aa --------

怎么把JS函数写到onclick里面
本帖最后由 menqi22 于 2013-01-12 14:59:14 编辑 // ----- popup_aa ------------------------
function pa()
{
  element      = document.getElementById('pa');
  drag_element = document.getElementById('pa_drag');
  exit_element = document.getElementById('pa_exit');
  element.style.position   = "absolute";
  element.style.visibility = "visible";
  element.style.display    = "block";
    element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-10)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-10)+'px';
  drag_element['target']   = 'pa';
  drag_element.onmousedown = popup_mousedown;
  exit_element.onclick     = popup_exit;
}

把函数pa()写到onclick事件里面 <a href="#" onclick="写到这里来"  >测试</a>
下面是完整代码,谢谢!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">



<script language="javascript">
var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;
function popup_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}
// ----- popup_mousedown -------------------------------------------------------
function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";
  if ( ie  &&  window.event.button != 1) return;
  if (!ie  &&  e.button            != 0) return;
  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;
  if (ie)
       popup_oldfunction      = document.onselectstart;
  else popup_oldfunction      = document.onmousedown;
  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}
// ----- popup_mousemove -------------------------------------------------------
function popup_mousemove(e)
{
  if (!popup_dragging) return;


  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  var mouseX = ie ? window.event.clientX : e.clientX;
  var mouseY = ie ? window.event.clientY : e.clientY;
  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';
  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}
// ----- popup_mouseup ---------------------
function popup_mouseup(e)
{
  if (!popup_dragging) return;
  popup_dragging = false;
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}
// ----- popup_exit ------------------------
function popup_exit(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  popup_mouseup(e);
  element.style.visibility = 'hidden';
  element.style.display    = 'none';
}

// ----- popup_aa ------------------------
function pa()
{
  element      = document.getElementById('pa');
  drag_element = document.getElementById('pa_drag');
  exit_element = document.getElementById('pa_exit');
  element.style.position   = "absolute";
  element.style.visibility = "visible";
  element.style.display    = "block";
    element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-10)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-10)+'px';
  drag_element['target']   = 'pa';
  drag_element.onmousedown = popup_mousedown;
  exit_element.onclick     = popup_exit;
}

// ----- popup_mousepos --------------------
function popup_mousepos(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";
  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}
// ----- Attach Events ---------------------
if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousedown', popup_mousepos);
else document.addEventListener('mousedown', popup_mousepos, false);


if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);
if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);

</script> 
 </head>



<a href="#" onclick="pa()"  >测试</a>
<div id="pa" style="visibility: hidden; display: none;">
<table  width="" cellspacing="0" cellpadding="0" border="0" onselectstart="return false;" style="-moz-user-select: -moz-none; font-size:12px; line-height:1.4;border-collapse: collapse;">
    <tr>
      <td width="13" height="33" style="background-image: url(images/dialog_lt.png) !important;background: url(images/dialog_lt.gif) no-repeat 0 0;"><div style="width: 13px;"></div></td>
      
  <td id="pa_drag" height="33" style="background-image:url(images/dialog_ct.png) !important;background: url(images/dialog_ct.gif) repeat-x top;"><div  style="padding: 9px 0 0 4px; float: left; font-weight: bold; color:#fff;"><img align="absmiddle" src="images/icon_dialog.gif"/>窗口标题</div>
        
<div id="pa_exit" onmouseout="this.style.backgroundImage='url(images/dialog_closebtn.gif)'" onmouseover="this.style.backgroundImage='url(images/dialog_closebtn_over.gif)'" style="margin: 4px 0 0;*margin-top: 5px; position: relative;top:auto; cursor: pointer; float: right; height: 17px; width: 28px; background: url(images/dialog_closebtn.gif) 0 0;' + (ielt7 ? "margin-top: 3px;" : "") + (this.ShowCloseButton ? "" : "display:none;") + '"></div></td>
      <td width="13" height="33" style="background-image: url(images/dialog_rt.png) !important;background: url(images/dialog_rt.gif) no-repeat right 0;"></td>
    </tr>
    <tr valign="top">
      <td width="13" style="background-image: url(images/dialog_mlm.png) !important;background: url(images/dialog_mlm.gif) repeat-y left;"></td>
      <td align="center">
     <table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
          <tr>
            <td valign="top" width="200" height="180">
<textarea rows="3" cols="30" readonly>买家备注:<%=T_customerneeds%></textarea>
<textarea rows="3" cols="30" readonly>卖家备注:<%=T_AppendRemark%><%=T_Remark%></textarea>
<form  method=post action="addremark2.asp?TradeNO=<%=T_TradeNO%>">
<textarea cols=30 rows=3 type=text name=APP_Remark></textarea>
<input type=submit value=确定 class=btn1_mouseout  style=height:25px;width:50px;FONT-SIZE:15px;>


</form>
              </td>
          </tr>
        </table></td>
      <td width="13" style="background-image: url(images/dialog_mrm.png) !important;background: url(images/dialog_mrm.gif) repeat-y right;"></td>
    </tr>
    <tr>
      <td width="13" height="13" style="background-image: url(images/dialog_lb.png) !important;background: url(images/dialog_lb.gif) no-repeat 0 bottom;"></td>
      <td style="background-image: url(images/dialog_cb.png) !important;background: url(images/dialog_cb.gif) repeat-x bottom;"></td>
      <td width="13" height="13" style="background-image: url(images/dialog_rb.png) !important;background: url(images/dialog_rb.gif) no-repeat right bottom;"></td>
    </tr>
  </table>
  </div>


[解决办法]

<a href="#" onclick="return pa();"  >测试</a>

热点排行