你好,当我点击一个按钮响应发生2次时,我有这种眩晕行为,我不明白发生了什么???
这是javascript的代码:
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);
}
});
}}
这是页面的代码......
<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"><!--Comment--></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>
感谢。
答案 0 :(得分:1)
如果在绑定事件之前取消绑定事件,则会阻止它们被意外绑定两次。所以,如果在行之前:
$( “#showhid”)。单击(功能(事件){
你说这个:
$( '#showhid')解除绑定( '点击');
在此之前:
$( “#createBt”)。单击(功能(事件){
你说这个:
$( '#createBt')解除绑定( '点击');
这可以解决您的问题。