Hy,我有一個女巫的形式,我有一些選擇框,我用一個小而簡單的小jquery插件來幫助我設計它們。Jquery問題的方法
$.fn.extend({
customSelect : function(options) {
if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
return this.each(function() {
var outerClass = options.customClass,
innerClass = options.customClass_inner;
var currentSelected = $(this).find(':selected');
var html = currentSelected.html();
if(!html){ html=' '; }
$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+html+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
var selectBoxSpan = $(this).next();
var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));
var selectBoxSpanInner = selectBoxSpan.find(':first-child');
selectBoxSpan.css({display:'inline-block'});
selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
$(this).height(selectBoxHeight).change(function(){
selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
});
});
}
}
});
$('select').customSelect();
而且它的確定,它的偉大工程,問題是,我也有,如果你點擊廣告,其越來越多的選擇框,只要你想盡可能多的按鈕(沒關係原因:P)。 這些選擇框也是在jquery的幫助下創建的,所以我將它動態添加到dom中。
所以我的問題是,這些新的選擇框當然不會繼承樣式,我知道這是因爲我以後將它們添加到DOM,但是我可以讓它們繼承on方法的幫助?
謝謝,任何幫助!
我不知道你使用的是什麼版本的jQuery,但似乎值得注意的是['.browser'已被棄用](http://api.jquery.com/jquery.browser/)。 – 2012-04-26 11:06:15