2011-01-18 3 views
0

안녕하세요, 버튼을 클릭하면 응답이 2 번 발생하고 무슨 일이 벌어지는 지 이해하지 못합니다.클릭 이벤트에 대한 버튼이있는 Bizzare 동작

<HTML><HEAD><LINK href="http://dev.karinapp.com/modules/appgen/css/batute.css" id="css_batute_4" rel="stylesheet" type="text/css"/><LINK href="http://dev.karinapp.com/modules/batute/css/main.css" id="css_batute_22" rel="stylesheet" type="text/css"/><SCRIPT id="script0" src="http://dev.karinapp.com/modules/general/scripts/jQuery.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="script1" src="http://dev.karinapp.com/modules/general/scripts/ui/jquery.ui.core.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="script2" src="http://dev.karinapp.com/modules/general/scripts/ui/jquery.ui.widget.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="script3" src="http://dev.karinapp.com/modules/general/scripts/ui/jquery.ui.button.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="script4" src="/modules/general/scripts/general.js" type="text/javascript"><!--empty--></SCRIPT><LINK href="http://dev.karinapp.com/modules/general/css/karinapp-style/jquery-ui-1.8.4.custom.css" id="link4" rel="stylesheet" type="text/css"/><SCRIPT id="script5" src="/modules/appgen/scripts/batute.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="script6">function __init__(){ 

main(); 


}</SCRIPT><SCRIPT id="pdloadScr" src="/modules/general/scripts/loadPage.js" type="text/javascript"><!--empty--></SCRIPT><SCRIPT id="pdLoader" type="text/javascript">window.onload = function(){postLoad(); 
__init__();}</SCRIPT><SCRIPT id="script9" src="/modules/general/scripts/Catcher.js" type="text/javascript"><!--empty--></SCRIPT></HEAD><BODY id="body" key="fb4d1c88bad8893b8ca3ee30b19bf4190d378552"><DIV father="body" id="btcreator"> 
      <!--Comment--> 

      <LABEL father="@btcreator" id="fncNm_lbl"><!--empty-->    Name: 
      </LABEL> 

      <LABEL father="@btcreator" id="fatherlbl"><!--empty-->Father: 
      </LABEL> 
      <INPUT father="@btcreator" id="fncnm" type="text"/> 
      <SELECT father="@btcreator" id="fatherbt"><!--Comment--><OPTION father="@fatherbt" id="fatherbt_Opt0" name="fatherbt_Opt0" value="none">No father</OPTION></SELECT> 

      <BUTTON father="@btcreator" id="createBt"><!--empty-->Create</BUTTON><SELECT father="@btcreator" id="fncName"><OPTION father="@fncName" id="fncName_Opt0" name="fncName_Opt0" value="default">Select one...</OPTION><OPTION father="@fncName" id="fncName_Opt1" name="fncName_Opt1" value="oper">Operation</OPTION><OPTION father="@fncName" id="fncName_Opt2" name="fncName_Opt2" value="dirls">List of directories</OPTION><OPTION father="@fncName" id="fncName_Opt3" name="fncName_Opt3" value="opnfl">Open File</OPTION><OPTION father="@fncName" id="fncName_Opt4" name="fncName_Opt4" value="delete">Delete File</OPTION><OPTION father="@fncName" id="fncName_Opt5" name="fncName_Opt5" value="compare">Compare</OPTION><OPTION father="@fncName" id="fncName_Opt6" name="fncName_Opt6" value="cp">Copy</OPTION><OPTION father="@fncName" id="fncName_Opt7" name="fncName_Opt7" value="get">Get</OPTION><OPTION father="@fncName" id="fncName_Opt8" name="fncName_Opt8" value="switch">Switch(If-Else)</OPTION><OPTION father="@fncName" id="fncName_Opt9" name="fncName_Opt9" value="upload">Upload</OPTION><OPTION father="@fncName" id="fncName_Opt10" name="fncName_Opt10" value="modify">Modify(Elements)</OPTION><OPTION father="@fncName" id="fncName_Opt11" name="fncName_Opt11" value="create">Create(Elements)</OPTION><OPTION father="@fncName" id="fncName_Opt12" name="fncName_Opt12" value="find">Select(SQL)</OPTION><OPTION father="@fncName" id="fncName_Opt13" name="fncName_Opt13" value="insert">Insert(SQL)</OPTION><OPTION father="@fncName" id="fncName_Opt14" name="fncName_Opt14" value="update">Update(SQL)</OPTION></SELECT><BUTTON father="@btcreator" id="addRpl" value="Add Reply"><!--empty-->Add Reply</BUTTON><LABEL father="@btcreator" id="fncNameLbl"><!--empty-->Function:</LABEL> 

      <DIV father="@btcreator" id="rplCrt"> 
       <!--Comment--> 
       <BUTTON father="@rplCrt" id="crtMdl" value="Create Model"><!--empty-->Create model</BUTTON> 
       <BUTTON father="@rplCrt" id="stcRpl" value="Add Static Reply"><!--empty-->Add static Reply</BUTTON> 
       <BUTTON father="@rplCrt" id="addMdl"><!--empty--></BUTTON><TEXTAREA cols="45" father="@rplCrt" id="insertStc" rows="15">&lt;!--Comment--&gt;</TEXTAREA><TABLE father="@rplCrt" id="mdlLst" width="90%"><THEAD father="@mdlLst" id="thead0"><TR> 
<TH width="50%">Function name:</TH> 
<TH>Select</TH> 

</TR></THEAD><TBODY father="@mdlLst" id="tbody0"/></TABLE><LABEL father="@rplCrt" id="insertMdlLbl"><!--empty-->Insert model on:</LABEL><INPUT father="@rplCrt" id="mdIns"/> 
      </DIV> 
     <LABEL father="@btcreator" for="dtype" id="dTypelbl">Data-Type:</LABEL><SELECT father="@btcreator" id="dtype"><!--Comment--><OPTION father="@dtype" id="dtype_Opt0" name="dtype_Opt0" value="data">Data</OPTION><OPTION father="@dtype" id="dtype_Opt1" name="dtype_Opt1" value="int">Integer</OPTION><OPTION father="@dtype" id="dtype_Opt2" name="dtype_Opt2" value="float">Float</OPTION><OPTION father="@dtype" id="dtype_Opt3" name="dtype_Opt3" value="str">String</OPTION><OPTION father="@dtype" id="dtype_Opt4" name="dtype_Opt4" value="list">Array/List</OPTION></SELECT></DIV><BUTTON father="body" id="showhid"> 
       <!--Comment--> 
      </BUTTON></BODY></HTML> 

감사합니다 ...

function main(){ 
//Creating the function that will be executed by the showhid. 
$("#showhid").click(function(event){ 
    if ($('#btcreator').is(":visible") === true){ 

     $(this).button({ 
      icons:{secondary:'ui-icon-arrowthick-1-w'}, 
      text:false}); 

     $(this).animate({left:'97%'}, 'fast'); 

     $('#btcreator').animate({width:'hide'}, 'fast'); 

     return; 
    }else if($('#btcreator').is(":visible") === false){ 

     $(this).button({ 
      icons:{secondary:'ui-icon-arrowthick-1-e'}, 
      text:false}); 

     $(this).animate({left:'522px'}, 'fast'); 

     $('#btcreator').animate({width:'show'}, 'fast'); 

     return; 
    } 
}); 


//Executing the button function on the createBt Button. 
$("#createBt").button(); 
//Creating the function that will create the batute. 
$("#createBt").click(function(event){ 
    if (getData('fatherbt') == 'none'){ 
     window.fileLoc="modules/appgen/devBt/"+$('#body').attr('key').substring(0, 5); 
     elMnt = window.operation.createElement('element'); 
     elMnt.setAttribute('name', 'attr'); 
     elMnt.setAttribute('id', 'idEl'); 
     elMnt.setAttribute('attrname', 'id'); 
     elMnt.setAttribute('vtype', 'str'); 
     elMnt.setAttribute('value', getData('fncnm')); 
     window.data_lst = [elMnt]; 
     elAttr = window.operation.createElement('element'); 
     elAttr.setAttribute('name', 'attr'); 
     elAttr.setAttribute('id', 'nameEl'); 
     elAttr.setAttribute('attrname', 'name'); 
     elAttr.setAttribute('vtype', 'str'); 
     elAttr.setAttribute('value', getData('fncName')); 
     window.data_lst.push(elAttr); 
     window.addEl = 'function'; 
     catcher('crtBt'); 
     alert(event.data); 
    } 
}); 
}} 

이 페이지의 코드 :

은 자바 스크립트의 코드입니다.

+0

로드하고있는 스크립트 중 하나가 어딘가에 'main()'을 호출 할 수 있습니까? 이 함수 이름은 전역 적으로 선언되므로 누구나 호출 할 수 있으며 거의 ​​고유 한 이름은 아닙니다. –

+0

주 기능의 이름이 변경되어 동일합니다. – hidura

답변

1

이벤트를 바인딩하기 전에 바인딩을 해제하면 이벤트가 실수로 두 번 바인딩되는 것을 방지 할 수 있습니다. 그래서 만약 줄 앞에 :

$ ("#의 showhid") 함수 (이벤트 (클릭) {당신이 넣어

:.

$를 ('#의 showhid') .unbind ('클릭');

을 그리고이 줄 앞에 :

. 0

$ ("#의 createBt") 함수 (이벤트 (클릭) {

당신이 넣어 :

$ ('#의 createBt')를() '을 클릭'바인딩 해제;.

이렇게하면 문제가 해결됩니다.

관련 문제