小编Dan*_*eel的帖子

简单的jquery总和

我有未知数量的输入字段,有类"添加"我只想用jquery来总结这些,不知道我错在哪里.

<input name="add" class="add" type="text">
<input name="add" class="add" type="text">
<input name="add" class="add" type="text">
<input name="add" class="add" type="text">

<input type="button" value="" onClick="add()" />
Run Code Online (Sandbox Code Playgroud)

`

function add(){
        val = 0;
        $(".add").each(function() {      
            str = (parseInt(this.value))
            sum=str+str
        });
        alert (sum)
    }
Run Code Online (Sandbox Code Playgroud)

`

math jquery sum

4
推荐指数
1
解决办法
3万
查看次数

运行函数后更改Google Maps Marker HTML

因此,我试图找出一种方法来更改Google Maps V3标记的HTML,这些标记在从数据库中提取之后但在被推送到数组之前.

当调用getFishing()时,我想运行convertRate(rate),这样如果rate变量等于2或更多,它会显示一个在Markers自身的HTML内的图片.我已经尝试将它放在bindInfoWindow4()中,并且我在getFishing()函数中尝试了几个地方但没有成功.有没有人这样做过?将标记推到fishArray之后是否可能?

     function getFishing() {
        fishingUrl("XML_Fishing.php", function (data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var id = markers[i].getAttribute("id");
                var title = markers[i].getAttribute("title");
                var rate = markers[i].getAttribute("rate");
                var Fishhtml = "<img id='1star' src='images/1star.png' style='visibility:hidden'>";
                var icon = FishingIcon;
                var Fishmark = new google.maps.Marker({
                    map: map,
                    position: point,
                    icon: icon.icon
                });
                fishArray.push(Fishmark);
                bindInfoWindow4(Fishmark, map, Fishinfo, Fishhtml);

            }
        });
    }
    function convertRate(rate) {
        if (rate >= 2) { …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps-api-3

3
推荐指数
1
解决办法
4061
查看次数

更新谷歌地图上的标记位置,无需加载页面

我试图在每20秒更新一次来自数据库的谷歌地图标记位置,但它不起作用.

代码:

for (i = 0; i < purple.length; i++) {

    if (purple[i][1] == latitude && purple[i][2] == longitude) {
        nogreen = 1;
    }

    marker = new google.maps.Marker({
            position : new google.maps.LatLng(purple[i][1], purple[i][2]),
            map : map,
            title : purple[i][0],
            data : purple[i][0],
            zoom : maxZoomService,
            icon : 'img/purple.png',
            shadow : 'img/purple.png'
        });

    setInterval(function () {
        position : new google.maps.LatLng(purple[i][1], purple[i][2]),
        marker.setPosition(position);
    }, 20000);
};
Run Code Online (Sandbox Code Playgroud)

这是正确的还是我该怎么做?

javascript google-maps google-maps-api-3

2
推荐指数
1
解决办法
1万
查看次数

Jquery验证插件字母数字方法接受点

我在用户名字段中有一个要求,我必须验证特殊字符,但允许'.' 点字符.我们在插件字母数字中有自定义方法,但它不允许使用点.请检查小提琴

jQuery.validator.addMethod("alphanumeric", function(value, element) {
    return this.optional(element) || /^\w+$/i.test(value);
}, "Letters, numbers, and . only please");
Run Code Online (Sandbox Code Playgroud)

html javascript validation jquery

2
推荐指数
1
解决办法
1万
查看次数