无法在这里找出问题所在。功能show()
之外的onSelectChange
效果很好,内部没有。如果未隐藏标签,则附加效果很好。
我的代码如下:
jQuery(document).ready(function(){
jQuery("#cityfrom").change(onSelectChange);
});
function onSelectChange(){
var selected = jQuery("#cityfrom option:selected");
if(selected.val() != 0){
selectedfrom = selected.text();
jQuery("#hidden").show();
jQuery("#append").text(selectedfrom);
}
}

#hidden{
display:none;
}

<label id="hidden"><input type="radio" name="start" value="xx"><span id="append"></span></label>
<select id="cityfrom">
<option value="" disabled selected>Izvēlies citu pilsētu</option>
<option name="pilseta" value="smiltene">Smiltene</option>
<option name="pilseta" value="valmiera">Valmiera</option>
</select>
&#13;
答案 0 :(得分:1)
您发布的代码段有两个基本问题(代码中没有实际问题!)
<script>
个标记
jQuery(document).ready(function() {
jQuery("#cityfrom").change(onSelectChange);
});
function onSelectChange() {
var selected = jQuery("#cityfrom option:selected");
if (selected.val() != 0) {
selectedfrom = selected.text();
jQuery("#hidden").show();
jQuery("#append").text(selectedfrom);
}
}
&#13;
#hidden {
display: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="hidden">
<input type="radio" name="start" value="xx"><span id="append"></span>
</label>
<select id="cityfrom">
<option value="" disabled selected>Izvēlies citu pilsētu</option>
<option name="pilseta" value="smiltene">Smiltene</option>
<option name="pilseta" value="valmiera">Valmiera</option>
</select>
&#13;