在服务器端选择选项错误,但在客户端运行

时间:2012-04-23 15:14:06

标签: php jquery

我有选择框,它有值和 client example

我的服务器代码如下

  <select name="customer_id" id="customer_id">
<?php get_customer_list_options(); ?>
  </select> | 
  <input id="customer_name_from_sel" type="text" />

以及jquery代码

<script type="text/javascript">
    $(document).ready(function(){

    $("#customer_id").bind('change', function() {
        var k = $("#customer_id option:selected").attr("title");
        $("#customer_name_from_sel").val(k);
    });

});​

</script>

和功能代码

function get_customer_list_options() {
    $fquery39 = mysql_query("select User_ID, First_Name, Email_ID from customers");

    while($r39 = mysql_fetch_row($fquery39)) {
        echo "<option value='$r39[0]' title='$r39[1]' >$r39[2]</option>";
    }

}

现在,当我从jsfiddle运行代码时,运行完美,而在服务器页面上,它无法运行。 我已经在工作jquery库是好的..处于完美状态。

文字title

上未显示值customer_name_from_sel

以下是HTML代码的图像输出。

enter image description here

错误图片

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您需要测试$("#customer_id option:selected")是否获得正确的元素。如果没有,您可以使用selectedIndex获取所选选项。