0

为什么这不起作用?

     <script>
     $(document).ready(function(){
     $('#custom_field option').click(function(){
        $('#custom_field_input').append('<tr><td></td></tr>');      
        $('#custom_field_input td:last').append($(this).find(":selected").text());
     });
     });
     </script>

我发现有一个 .change 函数,它可以工作,但与我无关,因为即使选择下拉列表的值没有变化,我也需要附加文本。

意义。

用户单击 option1,附加 option1 文本。

用户再次单击选项 1,附加了另一个选项 1 文本。

4

7 回答 7

0

您还可以从

http://www.guy.footring.net/randomStuff/selectBox.htm

于 2012-09-11T11:10:54.737 回答
0

使用以下代码使单击 custom_field_opition 时的 custon_field_input 元素为空:

<script>
 $(document).ready(function(){
 $('#custom_field option').click(function(){
  $('#custom_field_input').html('');      
    $('#custom_field_input').append('<tr><td></td></tr>');      
    $('#custom_field_input td:last').append($(this).find(":selected").text());
 });
 });
 </script>
于 2012-09-11T11:05:45.183 回答
0
<script>
 $(document).ready(function(){
 $('#custom_field').change(function(){
    $('#custom_field_input').append('<tr><td></td></tr>');      
    $('#custom_field_input td:last').append($(this).val());
 });
 });
 </script>

这也适用于您的情况

于 2012-09-11T11:06:06.960 回答
0

尝试

 <script>
     $(document).ready(function(){
     $('#custom_field option').click(function(){
     $('#custom_field_input').html('');      
     $('#custom_field_input').append('<tr><td></td></tr>');      
     $('#custom_field_input td:last').append($(this).find(":selected").text());
 });
 });
</script>
于 2012-09-11T11:06:48.770 回答
0

尝试这个。

jQuery(function () {
    jQuery('#custom_field').click(function () {
        jQuery("#custom_field_input").val(jQuery("#custom_field_input").val() + jQuery("option:selected", this).text());
    });
});
于 2012-09-11T16:32:06.873 回答
0

试试这个:做了 2 处更改。使用实时以防您的选择稍后动态填充。如果不使用简单的 .click()。也可以使用 .find("option:selected") 代替 .find(":selected")。

<script>
 $(document).ready(function(){
 $('#custom_field option').live('click',function(){
    $('#custom_field_input').append('<tr><td></td></tr>');      
    $('#custom_field_input td:last').append($(this).find("option:selected").text());
 });
 });
 </script>
于 2012-10-24T05:00:20.727 回答
0

您可以使用模糊或聚焦事件而不是单击。

$('#custom_field option').focusout(function(){
....
 });   

$('#custom_field option').blur(function(){
....
 });
于 2012-09-11T14:20:27.100 回答