简体   繁体   中英

using jquery .html(), i cant pass an id through to a function

sorry if confusing.. but i am this code:

$(document).ready(function(){
  $("button.yo1").click(function(){
    $("div.class1").html("<h1>&nbsp;</h1><h1><br /><select id='multi2' style='width:193px;'></select><br /></h1><button>Pick Class</button>")
  });
});

and 'multi2' can't be found .. do i have to pass a parameter or variable?. here is the function to get multi2

function childless() {

var s = document.getElementById('multi2');
var ar = [1,2,3];
for(var i=0; i<ar.length; i++) {
var option = document.createElement('option');
option.text = ar[i];
option.value = ar[i];
s.options[i] = option;
}

}

it works if i dont change the div, any ideas?

好吧,除非单击了button.yo1,否则无法调用childless()函数

$(document).ready(function(){
    $("button.yo1").click(function(){
        $("div.class1").html("<h1>&nbsp;</h1><h1><br /><select id='multi2' style='width:193px;'></select><br /></h1><button>Pick Class</button>");
        childless(); // <---call childless() after the HTML content has been added.
    });
});

Although I'd wonder why you want to recreate the content with each click of div.class1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM