簡體   English   中英

單擊事件上帶有按鈕的Bizzare行為

[英]Bizzare behavior with a button on the click event

您好,當我單擊一個按鈕時,響應出現了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">&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>

謝謝。

如果在綁定事件之前取消綁定事件,則可以防止事件被意外綁定兩次。 因此,如果在該行之前:

$(“#showhid”)。click(function(event){

你把這個:

$('#showhid')。unbind('click');

在此行之前:

$(“#createBt”)。click(function(event){

你把這個:

$('#createBt')。unbind('click');

這應該可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM