开发者

$.get() generated HTML are not recognized

In main.php, I have:

$('#GiveMeATextbox').click(function(){
  $.get('ReturnATextbox',{'jsample':'sample'}, function(d){$('#container').html(d); });
});

$('#IamReturnedTextbox').click(function(){
  alert("successful");
});

And my HTML

<div id="container">
    <input type="button" id="GiveMeATextbox"></input>
</div>

and in ReturnATextbox.php

echo "<input type="text" id="IamReturnedTextbo开发者_JAVA百科x"></input>"

My problem is that

$('#IamReturnedTextbox').click(function(){
  alert("successful");
});

won't work - it seems that the Main.php doesn't recognise the $.get generated HTML.

Any suggestions?


Alright! i believe the other people are missing the point.

if i am right you are already loading the content successfully.

the problem is you are trying to run a function on an element that doesnt exist until the $.get is fired.

two solutions.

//either a live call which will work on elements loaded into the dom after the initial page load
$('#IamReturnedTextbox').live("click",function(){ 
    alert("successful"); 
});

//or a callback on the $.get function
$.get("file here",function(){
    $('#IamReturnedTextbox').click(function(){ 
        alert("successful"); 
    });
)};

hope this helps!


you're missing the .php extension inside the $.get call.

you should write like this:

$.get('ReturnATextbox.php',{'jsample':'sample'}, function(d){$('#container').html(d); }); });


try this

$('#GiveMeATextbox').click(function(){ $.get('ReturnATextbox.php',{jsample:'sample'}, function(d){$('#container').html(d); }); });

Hope it'll work ^^

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜