开发者

jquery problem @.@

$('#save').click(
            function(){
  开发者_JS百科                              alert('run');
                update_form('get_form','main_content',true);
            }
); 

hi,i got a problem in my program..... please help me T.T.

above function is not run. i think the clue should be here.

$.ajax({
......
$('#' + divtoupdate).html("<input type='submit' id='save' name='save'  value='Save'/>");
})

all ajax part is ok, i think is because dom problem?, the click() is created before i run the ajax.(i have the action before i got the input) is this causing click function malfunction. any solution for this problem ^^ thx


You should use jQuery live


Yes..for the click function on 'save' button to work...it should be present when page is loaded...try running click after ajax function..it should work fine then.. Even Live function will work --- It will take care of element even if it is added in future.

$('#Save').live('click',function(){
//ur code here
});

But Live will not work on older browsers.


You need to use $.live to workout event handling on elements added dynamically.

$('#save').live('click', function(){ ... });


I think what you are trying to say is that the first bit of code won't work because the second bit of code hasn't run yet. This second bit of code adds the HTML which the first bit works upon.

In which case, try the live() function instead of click()


You need to add the click handler after the object is created. You could just add your existing handler code to the ajax success, after the line where you create the #save element.


Yeap, try putting your $('#save').click inside your ajax callback function.

$.ajax({
......
$('#' + divtoupdate).html("<input type='submit' id='save' name='save'  value='Save'/>");
$('#save').click(
            function(){
                                alert('run');
                update_form('get_form','main_content',true);
            }
); 
})


try out this...add the function after you add the actual element...

$.ajax({
......
$('#' + divtoupdate).html("<input type='submit' id='save' name='save'  value='Save'/>");
$('#save').click(
            function(){
                                alert('run');
                update_form('get_form','main_content',true);
            }
);

})


$(document).ready(function() { var waterVolume function initialFill(){ waterVolume = Math.floor(Math.random() * (150000 - 50000 + 1)) + 50000 initialWidth = $('.resizable_tank').width() initialHeight = $('.resizable_tank').height() stabilizeWaterPipe(initialWidth,initialHeight) }

function stabilizeWaterPipe(currentWidth,currentHeight) {
    stableHeight = $('.resizable_tank_pipe').offset().top + $('.resizable_tank_pipe').height() + 8
    $('.stable_tank_pipe').css({height: (stableHeight-400)+"px", bottom: "-"+(stableHeight-400)+"px"})
    stabilizeCalc(currentWidth,currentHeight)
}

function stabilizeCalc(currentWidth,currentHeight) {
    stableTankWidth = $('.stable_tank').width()
    stableTankHeight = $('.stable_tank').height()
    increasedHeight = parseFloat(currentHeight - stableTankHeight)

    // im getting problem here with filling and make equal levels of water in both the cylinders would u pls help me with some code .
}

$('.resizable_tank').resizable({
    handles: 'e,s,se',
    maxWidth: 800,
    minWidth: 180,
    minHeight: 400,
    resize: function(event, ui) {
        var currentWidth = ui.size.width;
        var currentHeight = ui.size.height;
        stabilizeWaterPipe(currentWidth,currentHeight)
    }
})

initialFill()

});

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜