【jQuery】on注册事件的时候处理函数自动运行

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012837895/article/details/77824050
<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    var Circle={
        x:405,
        y:305,
        Radius:300
    };
    var arr=new Array();//存放event
    var rangeArr=new Array();//存放区间
    $("#createEvent").on("click",function(){
        if($("#input").children()[0].value==""){
            $("#warn").text("请输入内容!");
        }
        else{
            arr.push({
                event: $("#input").children()[0].value,
                color: $("#input").children()[1].value
            });
            var $addButton=$("<button class='createNode'>+</button>");
            var $deleteButton=$("<button class='deleteNode'>x</button>");
            var $newList=$("<li name="+arr.length+">"+$("#input").children()[0].value+" "+$("#input").children()[1].value+"</li>");

            $newList.append($addButton);
            $newList.append($deleteButton);
            $("#table").append($newList);
            $("#table").on("click",{value:arr.length},".createNode",drawAfterClick(event));
        }

        function drawAfterClick(event){
            alert(1);
            alert(event.data.value);
        }
});

    });
    </script>
</head>

<body>
    <div id="info">
        <form id="input">
            事件:<input type="text" name="事件名称"/>
            颜色:<select name="color"/>
            <option value="red">Red</option>
            <option value="yellow">Yellow</option>
            <option value="green">Green</option>
            <option value="blue">Blue</option>
            <option value="orange">Orange</option>
            <option value="brown">Brown</option>
            <option value="purple">Purple</option>
            </select>
        </form>
        <button id="createEvent">创建事件</button>
        <ul id="table">
            <li>事件 颜色</li>
        </ul>
    </div>
</body>
</html>

问题描述:在输入框输入内容,点击“创建事件”按纽之后,原来被绑定到新建立开关的函数会自动执行,怀疑与委托事件有关。



                                    
展开阅读全文

链表处理函数运行出错

10-30

有LinkFunSeries.cpp和LinkMain.cpp两个源文件,LinkFunSeries.cpp里是各个链表处理函数的定义,LinkMain.cpp是对链表处理函数简单调用以验证其正确性。rn代码如下:rnLinkFunSeries.cpprn[code=C/C++]rn#include rnusing namespace std;rn#ifndef LinkFunSeries_V_Mrn#define LinkFunSeries_V_Mrnstruct studentint num;float score;struct student *next;;rnvoid DelOne(struct student*head,struct student *q)//无序表删除一个节点,q为待删除节点rn rn struct student *p=head;rn if(p==q)rn head=head->next;rn elsern rn while(p->next!=q)rn p=p->next;rn p->next=q->next;rn rn delete q;rnrnvoid DelSort(struct student*head,struct student *q)rn //有序表删除一个节点,被删节点后所有节点序号自减1rn struct student *p=head; rn if(p==q)rn rn p=head=head->next;rn p->num--;rn rn elsern rn while(p->next!=q)rn p=p->next;rn p->next=q->next;rn rn delete q;rn while(p->next!=NULL)rn rn p=p->next;rn p->num--;rn rnrnrnstruct student *CreatNoSort() //手动输入无序链表rnrn struct student *head,*p1,*p2;rn p1=new student;rn cin>>p1->num>>p1->score;rn head=p2=p1;rn while(p1->num!=0)rn rn p1=new student;rn cin>>p1->num>>p1->score;rn p2->next=p1;rn p2=p1;rn rn p1->next=NULL;rn DelOne(head,p2); //删掉最后作为结束创建的节点,因为那个节点无实际意义rn return head;rnrnrnstruct student *Creat() //手动输入递增序号链表,序号不得重复rnrn struct student *head,*p1,*p2;rn p1=new student;rn cin>>p1->num>>p1->score;rn head=p2=p1;rn while(p1->score>=0)rn rn p1=new student;rn p2->next=p1;rn mark: cin>>p1->num>>p1->score;rn if(p1->num<=p2->num)rn rn cout<<"输入错误,序号必须递增,请重新输入:\n";rn goto mark;rn rn p2=p1;rn rn p1->next=NULL;rn DelOne(head,p2);rn return head;rn rn rnstruct student *CreatAuto() //创建自动生成递增序号的链表rnrn struct student *head,*p1,*p2;rn int i=1;rn p1=new student;rn p1->num=i;rn cin>>p1->score;rn head=p2=p1;rn while(p1->score<0) //由于num自动生成,以score为负作为创建结束条件rn rn p1=new student;rn p2->next=p1;rn p1->num=++i;rn cin>>p1->score;rn p2=p1;rn rn p1->next=NULL;rn DelOne(head,p2);rn return head;rn rnrn void PrintAll(struct student *head)rn rn struct student *p;rn p=head;rn while(p!=NULL)rn rn cout<<"#"<num<<','<<"score:"<score<next;rn rn rnrnstruct student *GetOne(struct student *head,int num)rnrn struct student *p;rn int n=0;rn p=head;rn while(p->num!=num&&p!=NULL)rn p=p->next;rn return p;rnrnrnvoid Insert(struct student *head,struct student *q)rnrn struct student *p1,*p2;rn p1=head;rn while(p1->numnum && p1!=NULL)rn rn p2=p1;rn p1=p1->next;rn rn if(head!=p1)rn rn q->next=p1;rn p2->next=q;rn p2=q;rn while(p2->num==p1->num)rn rn p1->num++;rn p2=p1;rn p1=p1->next;rn rn rn elsern rn q->next=head;rn head=q;rn rnrnrnvoid sort(struct student *head) //选择排序,rnrn struct student *p1,*p2,*min,*pmin; rn //p1指向每次新排好序的最小值,p2为遍历游标,pmin为最小节点前驱,min保存每趟遍历的最小值rn p1=p2=min=head;rn while(p2->next!=NULL) //先使head为最小值,找出num最小的节点rn rn if(min->num>p2->next->num)rn rn pmin=p2;rn min=p2->next;rn rn p2=p2->next;rn rn if(head!=min) //使min前驱为head,然后使head=minrn rn min->next=head;rn head=min;rn p1=head;rn rn min=p2=head->next; //min和p2指向未排序部分的第一节点。rn while(p1!=NULL) //第一重循环,把每次未排序部分的最小值放在该部分最前,p1前移一位指向该最小值rn rn while(p2->next!=NULL) //第二重循环,找出未排序部分的最小值rn rn if(min->num>p2->next->num)rn rn pmin=p2;rn min=p2->next;rn rn p2=p2->next;rn rn if(min!=p1->next) //min非无序部分第一位,进行min与首位交换rn rn pmin->next=min->next;rn min->next=p1->next;rn p1->next=min;rn rn p1=p1->next;rn min=p2=p1->next;rn rnrnvoid DelALL(struct student *head)rnrn struct student *p1,*p2;rn p1=p2=head;rn while(NULL!=p2)rn rn p2=p2->next;rn delete p1;rn p1=p2;rn rnrn#endifrn[/code]rnrnLinkMain.cpp[code=C/C++]rn#include rn#include "LinkFunSeries.cpp"rnusing namespace std;rnvoid main()rnrn struct student *head,*p,*q;rn int n;rn cout<<"创建无序表\n";rn head=CreatNoSort();rn PrintAll(head);rn cout<<"请输入要删除节点的序号值\n";rn cin>>n;rn p=GetOne(head,n);rn cout<<"Delete #"<num<<" score:"<score<>q->num>>q->score;rn Insert(head,q);rn PrintAll(head);rn DelALL(head);rnrn[/code]rn这两个源文件放在同一文件夹中,在vc6里打开LinkMain.cpp单文件编译运行,结果插入函数不能插入节点,删除节点若为删除头节点,则内存操作错误报警,求解救。 论坛

没有更多推荐了,返回首页