从jQuery源数组访问数据?

时间:2012-10-12 11:34:13

标签: php javascript jquery

ui设计师给了我这个代码,我不知道如何发布      选择源数组数据到PHP脚本所以我可以用MySQL查询它,对不起我      一个JQuery的初学者,我想像一个表单选项选择样式一样查询数组,或者使用关联数组会更好吗?

<div id='content'>
  <script type="text/javascript">
    $(document).ready(function () {
        var source = [
            "Select Your location",
            "North London",
            "South London",
            "West London",
            "East London",
            "City of London",  
        ];

        // Create a jqxDropDownList  
        $("#jqxDropDownList").jqxDropDownList({ 
            source: source,    
            selectedIndex: 0, 
            width:   '250px', 
            height: '35px', 
            theme: 'summer' 
        });
    });
</script>
<div id='jqxDropDownList'>

1 个答案:

答案 0 :(得分:2)

如果你只需要将这个花哨的下拉列表用作正常的下拉列表,这里就是一个例子(不需要ajax):

<html>
<head>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxdropdownlist.js"></script>

</head>
<body>
<div id='content'>
  <script type="text/javascript">
    $(document).ready(function () {
        var source = [
            "Select Your location",
            "North London",
            "South London",
            "West London",
            "East London",
            "City of London",  
        ];

        // Create a jqxDropDownList  
        $("#jqxDropDownList").jqxDropDownList({ 
            source: source,    
            selectedIndex: 0, 
            width:   '250px', 
            height: '35px', 
            theme: 'summer' 
        });

        $('#jqxDropDownList').bind('select', function (event) { 
            $('#location').val($("#jqxDropDownList").jqxDropDownList('getSelectedItem').label);        
        });

    });


</script>
<div id='jqxDropDownList'></div>

<form>
<input type="text" id="location" name="location" value="not selected" />
<input type="submit" value="selected!">
</form>

<div><?php if (isset($_GET['location'])) print('You selected: '.$_GET['location']); ?></div>

</div>
</body>
</html>
  1. 下载并使用jqwidgets库。
  2. 将一个select事件绑定到jqwidgets下拉列表,它将选定的值放入普通(隐藏)表单元素。
  3. 以正常提交的值提交并在PHP中使用
  4. 更多信息:JQWidgets dropdown homepage