以下是我的程序代码:
<div id="sp">
<div style="line-height:22px;background:#fafafa;padding:5px;">Select a language</div>
<div style="padding:10px">
<input type="radio" name="lang" value="01"><span>Java</span><br/>
<input type="radio" name="lang" value="02"><span>C#</span><br/>
<input type="radio" name="lang" value="03"><span>Ruby</span><br/>
<input type="radio" name="lang" value="04"><span>Basic</span><br/>
<input type="radio" name="lang" value="05"><span>Other</span>
</div>
</div>
<script type="text/javascript">
$(function(){
$('#sp').appendTo($('#cc').combo('panel'));
$('#sp input').click(function(){
var v = $(this).val();
var s = $(this).next('span').text();
$('#cc').combo('setValue', v).combo('setText', s).combo('hidePanel');
});
});
</script>
如果用户选择&#39;其他&#39;单选按钮我想显示一个文本框,以便用户输入另一种语言的名称。
答案 0 :(得分:0)
你的意思是这样的
<span class='other'>Other</span> //add a class
$("#sp .other").click(function(){
$("<input type='textbox' name='other'/>").insertAfter($(this))
})
答案 1 :(得分:0)
我希望以下代码可以帮助您。
<div id="sp">
<div style="line-height: 22px; background: #fafafa; padding: 5px;">Select a language</div>
<div style="padding: 10px">
<input type="radio" name="lang" value="01"><span>Java</span><br />
<input type="radio" name="lang" value="02"><span>C#</span><br />
<input type="radio" name="lang" value="03"><span>Ruby</span><br />
<input type="radio" name="lang" value="04"><span>Basic</span><br />
<input type="radio" name="lang" value="05"><span>Other</span>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#sp').change(function () {
var selectedValue = $('#sp :radio:checked').val();
if (selectedValue == "05") {
var addedlangualge = prompt('Add New Language :');
$('#sp').append('<input type="radio" name="lang" value="' + addedlangualge + '" checked="checked"><span>' + addedlangualge + '</span>');
}
});
});
</script>