创建的jQuery元素不是jQuery样式
我是JavaScript和jQuery的新手。请原谅我的任何愚蠢的编码错误或我肮脏的风格。我很高兴从你们经验丰富的方面得到所有建设性的反馈 我尝试动态添加一些jQuery元素,比如一些新的选择菜单。在我的例子中,用户应该决定他想要定制多少辆车,并基于此,我想要为每辆车创建一个新的选择菜单 如果用户选择“2辆车”,jQuery将添加两个新的选择菜单。但我的问题是,这些菜单不再是jQuery风格 我做错了什么?是否也可以根据选择的车辆数量在“for循环”中添加新菜单 这是我的密码:创建的jQuery元素不是jQuery样式,jquery,styles,Jquery,Styles,我是JavaScript和jQuery的新手。请原谅我的任何愚蠢的编码错误或我肮脏的风格。我很高兴从你们经验丰富的方面得到所有建设性的反馈 我尝试动态添加一些jQuery元素,比如一些新的选择菜单。在我的例子中,用户应该决定他想要定制多少辆车,并基于此,我想要为每辆车创建一个新的选择菜单 如果用户选择“2辆车”,jQuery将添加两个新的选择菜单。但我的问题是,这些菜单不再是jQuery风格 我做错了什么?是否也可以根据选择的车辆数量在“for循环”中添加新菜单 这是我的密码: <scri
<script type="text/javascript">
$('#select-choice-1').live( "change", function(event, ui) {
var valuee = $(this).val();
if (valuee == '2') ($('<label for="select-choice-2" class="select">Color of car #1</label>' +
'<select name="select-choice-2" id="select-choice-2">'+
'<option value="red">red</option>'+
'<option value="blue">blue</option>'+
'</select><br><br>' +
'<label for="select-choice-3" class="select">Color of car #2</label>' +
'<select name="select-choice-3" id="select-choice-3">'+
'<option value="green">green</option>'+
'<option value="yellow">yellow</option>'+
'</select>').appendTo('#site'));
if (valuee == '3') ($('<h1>Test</h1>').appendTo('#site'));
});
</script>
$('#select-choice-1')。实时(“更改”,函数(事件,用户界面){
var valuee=$(this.val();
如果(valuee=='2')($('Color of car#1'+
''+
“红色”+
“蓝色”+
“
”+
“汽车颜色#2”+
''+
“绿色”+
“黄色”+
'')。附录('#站点');
如果(valuee=='3')($('Test')。附加到('#site'));
});
这是html页面:
<div id="site" data-role="fieldcontain">
<label for="select-choice-1" class="select">Number of cars</label>
<select name="select-choice-1" id="select-choice-1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div><!-- "site" -->
汽车数量
1.
2.
3.
$(“#站点”)。委托(“#选择-choice-1”,“更改”,函数(事件,用户界面){
var valuee=$(this.val();
var constructhtml='';
如果(valuee=='2'){
constructhtml++='car颜色#1'+'''+'red'+'blue'+'
'+'car颜色#2'+'+'+'+'green'+'yellow'+';
}else if(valuee=='3'){
constructhtml+='Test';
}
$('#site').append(html);
});
OP需要创建一个动态添加的选择菜单
把这个div放在页面的最底部
<div id="selectcontainer"></div>
$(document).ready(function(){
var str = '';
str+='<select>';
for(i=1;i<=10;i++){
str+='<option value='"+i+"'>'"+i+"'</option>';
}
str+='</select>';
$('#selectcontainer').html(str);
});
$(文档).ready(函数(){
var-str='';
str+='';
对于(i=1;i)“jQuery风格”是什么意思?它看起来就像普通的html样式。没有阴影,只是一个老式的选择字段:如果你说的jQuery样式是指jQuery ui样式,那么你需要向你的html中添加与jQuery ui相同的类。你想怎么做?如果你想拥有自己的样式,那么就添加css并将这些类添加到这些元素中可能是一些css设计问题..我添加了一些调整(删除live
并添加了格式)我只是使用了原始的jquery.css,没有做任何更改。我不想要任何新样式,我只想让新的选择菜单看起来像普通的jquery选择菜单如果你使用firebug和Mozilla。分析选择菜单,看看哪种样式适用于它firebug没有在测试页面打开确定然后删除该选择菜单的任何类在jquery.css注释样式中,与select..相关,然后重试
<div id="selectcontainer"></div>
$(document).ready(function(){
var str = '';
str+='<select>';
for(i=1;i<=10;i++){
str+='<option value='"+i+"'>'"+i+"'</option>';
}
str+='</select>';
$('#selectcontainer').html(str);
});