before starting, just let my say that my background is primarily in graphic design, therefore my knowledge of coding is ... limited! So be gentle :D

在开始之前,让我说我的背景主要是图形设计,因此我的编码知识是有限的!所以要温柔:D

Here my situation: I'm building a phonegap app for android with google maps api \ fusion tables \ jquery mobile. I've a list of checkboxes that trigger various type of markers from fusion tables, I've passed the state of checkboxes via jquery. Here's the function that filters the elements from the fusion tables:

在这里我的情况:我正在使用谷歌地图api \ fusion tables \ jquery mobile为Android构建一个phonegap应用程序。我有一个复选框列表,从复合表中触发各种类型的标记,我通过jquery传递了复选框的状态。这是从融合表中过滤元素的函数:

function toggleMarkers(layer2) { 
    var fusione = TABLE ID ;
    var arr_numero = [];
    var idx = 0;
    if (document.getElementById('toggleID').checked)   { 
        arr_numero[idx] = 1;
        idx++;
    }                                    
    lista_numero = arr_numero.join(',');
    if (lista_numero == "") {
        lista_numero = "'no_selection'";
    }
    layer2.setQuery("SELECT Location FROM "+ fusione +" WHERE numero IN (" + lista_numero + ")");
}

... here's the checkbox:

...这是复选框:

<input type="checkbox" id="MYID" onclick="toggleMarkers(layer2);" />

.. and the JQ that "enables" the checkbox:

..以及“启用”复选框的JQ:

$(document).ready( function(){ 
  $("#toggleID").change(function() {toggleMarkers(layer2);});
});

SO, ;) this solution works pretty well but I would like to switch to select and option tags so it uses the native list UI of the OS!

SO ,;)这个解决方案工作得很好,但我想切换到选择和选项标签,所以它使用操作系统的本机列表UI!

Something like this:

像这样的东西:

<select  size="1" id="listazza" multiple="multiple">

  <option onclick="toggleMarkers(layer2);" onselect="toggleMarkers(layer2);" value="2" id="toggleID">ID</option>  

</select>

What kind of code do I have to use in JQ to trigger the option tag value?

我必须在JQ中使用哪种代码来触发选项标记值?

Hope this is clear enough, thanks in advance.

希望这很清楚,在此先感谢。

1 个解决方案

#1


1

Assuming I've understood your question correctly, the code for handling changes to a select list should be exactly the same as your checkbox example, but with the Id changed:

假设我已正确理解您的问题,处理选择列表更改的代码应与复选框示例完全相同,但ID已更改:

$(document).ready( function(){ 
    $("#listazza").change(function() { toggleMarkers(layer2); });
});

You can also remove the ugly onclick and onselect attributes from your HTML, as if you amend the above line of jQuery, this will take care of those for you too:

您还可以从HTML中删除丑陋的onclick和onselect属性,就像修改上面的jQuery行一样,这也将为您处理这些:

$(document).ready( function(){ 
    $("#listazza").live("change click", function() { toggleMarkers(layer2); });
})

HTML

HTML

<select id="listazza" multiple="multiple" size="1">
    <option value="2">ID</option>
</select>

更多相关文章

  1. 将JavaScript数组转换成逗号分隔列表的简单方法?
  2. 在Ajax请求后添加了自闭标记
  3. 使用Ajax+JQuery构造分页查询列表
  4. 如何使用jQuery选择列表中的最后X项?
  5. 删除一个HTML标记,但是保留innerHtml
  6. 单击列表项时如何编写内容? [重复]
  7. 在Paragraph标记中添加“名称”以使用POST
  8. 从下拉列表中获取复选框的值
  9. 未捕获的ReferenceError:函数未定义,它标记

随机推荐

  1. TabHost布局及新浪式TabHost布局
  2. android英语字典(内含源码哦)
  3. android 模拟器启动不了
  4. Android manifest之系统自带的permission
  5. Flutter之原生交互(Android)
  6. Android系列学习:handler,HandlerThread
  7. Android-View的滑动
  8. [Android]ScrollView和ListView套用冲突
  9. 狂刷Android范例之2:剪贴板范例
  10. 转:深入解读Linux与Android的相互关系