开发者

how to end a jquery function on click

开发者 https://www.devze.com 2023-02-13 11:58 出处:网络
I currently using a jQuery slug plugin to create a project slug bas开发者_Go百科ed on the title box. This works great. What I\'m having troube doing is only updating the slug when the user clicks the

I currently using a jQuery slug plugin to create a project slug bas开发者_Go百科ed on the title box. This works great. What I'm having troube doing is only updating the slug when the user clicks the edit link. Right now when the edit link is called the slug function is initiated and that works fine but when the "done" link is clicked I need to find a way to turn off the slug function. I hope that makes sense.

    $('#edit_slug').click(function() {
    //allow user to edit the project slug
    $("#edit_project_name").stringToSlug({  //this is the slug plugin
        getPut: '.project_slug',
        hide: false
    });
    $('input.project_slug').show(); //show the input
    $('input.project_slug').next("span").remove().end(); //remove the span with the slug
    $('#edit_slug').hide(); //hide edit link
    $('input.project_slug').after(" <a href='#' id='done_edit_slug'>Done</a>"); //show done link 
});

//if the user is done editing the slug show the span with the slug in it
$('#done_edit_slug').live('click', function() {
        $("#edit_project_name").stringToSlug().end(); //my attempt to make the function end
        $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>"); //show the slug as a span
        $('input.project_slug').hide(); //hide the input box
        $('#done_edit_slug').remove().end(); //remove done link
        $('#edit_slug').show(); //show edit link


});

I'm not sure this is the best way to acomplish this and i'm open to ideas. The main thing is I'm unsure how to end the stringToSlug() function when #done_edit_slug is clicked.

Thanks!


In your done event handler try unbinding the events on your textbox.

$('#done_edit_slug').live('click', function() {
        $("#edit_project_name").unbind("keyup keydown blur");
        $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>");
        $('input.project_slug').hide();
        $('#done_edit_slug').remove().end(); 
        $('#edit_slug').show();
});

This is done assuming you are using the default events in the plugin source.

0

精彩评论

暂无评论...
验证码 换一张
取 消