开发者

Can't find form element

开发者 https://www.devze.com 2023-01-21 04:01 出处:网络
I have used jquery to load 开发者_如何学Gosome html from another page and added the content to a div called \'console\'. This happens when I press a link:

I have used jquery to load 开发者_如何学Gosome html from another page and added the content to a div called 'console'. This happens when I press a link: $ ('# Console'). Load (this.href + '# container');

I try then to retrieve the form which is part of the added html. I use $('#formname') but I can not get the form element.

Why? What should I do?


The .load() method is lower case, like this:

$('#Console').load(this.href + ' #container');

Also make sure you're looking for it after it loads, like this:

$('#Console').load(this.href + ' #container', function() {
  var form = $('#formid');
});


Check your html you are putting in does the form also have an id attribute? As # is used in jQuery as the id selector.

$("[name=formname]") // if you need to use the name

Selectors: http://api.jquery.com/category/selectors/


Make sure you are trying to retrieve the form on complete of the ajax load. Ajax is happening asynchronously remember.

should look like this:

$('#Console').load(this.href + ' #container', function(){
    $('#formname'); // get form here
});

also check you syntax in the load url string. Need to have a space before the '#container'

0

精彩评论

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