猿问

onchange 无法获取正确的值

我在获取 onchange 函数的输入值时遇到问题。下面是我的编码:


 <div class="form-group">

 <label>Choose Book:<span style="color:red;">&nbsp;*</span></label>

 <select class="form-control" id="publisher" name="publisher" title="publisher">

 <option value="">Please Select</option>

 <?php

 $sql_branch = 'select * from book_lending where status=1 order by id';

 $arr_branch = db_conn_select($sql_branch);

 foreach ($arr_branch as $rs_branch) {

 echo '<option value="' . $rs_branch['id'] . '">' . $rs_branch['title'] . '</option>';

 }

 ?>

</select>

  </div>



 <div class="form-group">

 <label for="cp1" class="control-label">Book Stock<span style="color:red;">&nbsp;*</span></label>

 <input readonly="readonly" type="text" class="form-control" id="editor" name="editor" title="editor" value="" >

 </div>


<script>

$(function(){

    $("#publisher").change(function(){

        var displayid=$("#publisher option:selected").text();

        $("editor").val(displayid);

    })

})

</script>

下面是输出图片:

如果我在 id is publisher 中 onchange 我需要显示输入值,然后 id editor 将显示该值。希望有人能指导我我弄错了哪一部分。谢谢。



慕容森
浏览 164回答 2
2回答

qq_笑_17

您缺少编辑器 ID$(function(){&nbsp; &nbsp; $("#publisher").change(function(){&nbsp; &nbsp; &nbsp; &nbsp; var displayid=$(this).val();&nbsp; &nbsp; &nbsp; &nbsp; $("#editor").val(displayid);&nbsp; &nbsp; })})

泛舟湖上清波郎朗

尝试这个:-<script>$(function(){&nbsp; &nbsp; $("#publisher").change(function(){&nbsp; &nbsp; &nbsp; &nbsp; var value=$("#publisher").val();&nbsp; &nbsp; &nbsp; &nbsp; $("#editor").val(value);&nbsp; &nbsp; })})</script>
随时随地看视频慕课网APP
我要回答