【问题标题】:handling of checkboxes in an openWindow处理 openWindow 中的复选框
【发布时间】:2013-09-23 17:22:03
【问题描述】:

我想在右键单击标记时显示一个信息窗口。
infoWindow 必须根据值显示 4 个复选框。

google.maps.event.addListener(marker,"rightclick", function()
    { 
        html = "<table><tr><td>";
        if (value1==...) 
        {
            html = html + "<input type='checkbox' id='option1' checked>value1<br>";
        }
        else
        {
            html = html + "<input type='checkbox' id='option1'>value1<br>";    
        }
        if (value2==...) 
        {
            html = html + "<input type='checkbox' id='option2'checked>value2<br>";
        }
        else
        {
            html = html + "<input type='checkbox' id='option2' >value2<br>"; 
        }
        if (value3==...) 
        {
            html = html + "<input type='checkbox' id='option3' checked>value3<br>";
        }
        else
        {
            html = html + "<input type='checkbox' id='option3' >value3<br>";   
        }
        if (value4==...) 
        {
            html = html + "<input type='checkbox' id='option4' checked>value4<br>"; 
        }
        else
        {
            html = html + "<input type='checkbox' id='option4' >value4<br>"; 
        }
        html = html + "</td></tr></table>";
        marker.setContent(html)
        infoWindow.open(map,marker);    
    });

1) 是否因为这段代码不优雅而使用 jquery 实现了更好的实现?
2)如果我点击复选框#N,如何修改对应valueN的值?

【问题讨论】:

  • dafuq 为什么不 += 和为什么不 SWITCH!!!?
  • 如果要测试不同的变量,如何使用 switch?
  • 可以使用 switch 和 += 以及 jquery 呢?

标签: javascript jquery html google-maps-api-3


【解决方案1】:

类似的东西

var 
 values = [],
 html = '';

for(i=1;i<n;i++) {
 html += '<input type="checkbox" id="option"'+i+'" '+(values[i] == 'something' ? 'checked' : '')+'> value '+i+'<br/>';
}

【讨论】:

  • 这是针对问题的 javascript 部分的。我怎么知道使用 jquery 设置/取消设置了一个复选框?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-05
  • 2014-12-11
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
相关资源
最近更新 更多