Jquery 选择标签\带有融合表的复选框
在开始之前,我想说的是,我的背景主要是图形设计,因此我的编码知识......有限!所以要温柔一点:D
这是我的情况:我正在使用 google 地图 api \ fusion table \ 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 + ")");
}
...这是复选框:
<input type="checkbox" id="MYID" onclick="toggleMarkers(layer2);" />
.. 以及“启用”复选框的 JQ:
$(document).ready( function(){
$("#toggleID").change(function() {toggleMarkers(layer2);});
});
SO,;) 这个解决方案工作得很好,但我想切换到选择和选项标签,因此它使用操作系统的本机列表 UI!
像这样:
<select size="1" id="listazza" multiple="multiple">
<option onclick="toggleMarkers(layer2);" onselect="toggleMarkers(layer2);" value="2" id="toggleID">ID</option>
</select>
我必须在 JQ 中使用什么样的代码来触发选项标记值?
希望这足够清楚,提前致谢。
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
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:
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:
$(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!
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?
Hope this is clear enough, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设我正确理解了您的问题,处理选择列表更改的代码应该与您的复选框示例完全相同,但是
Id
发生了变化:您还可以删除丑陋的
HTML 中的 onclick
和onselect
属性,就像修改上面的 jQuery 行一样,这也会为您处理这些:HTML
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:You can also remove the ugly
onclick
andonselect
attributes from your HTML, as if you amend the above line of jQuery, this will take care of those for you too:HTML