首先,我values从 a得到所有的php array:<?php $user_id = get_current_user_id(); $userPostsInternal = get_user_meta( $user_id, 'save_post_internal', TRUE ); $userPostsExternal = get_user_meta( $user_id, 'save_post_external', TRUE )?>然后我得到这些arrays并将它们转换为JS arrayvar savedInternal = "<?php echo $userPostsInternal; ?>";var savedExternal = "<?php echo $userPostsExternal; ?>";savedInternal = savedInternal.split(',');savedExternal = savedExternal.split(',');然后我需要检查电流id value是否在其中js array并相应地进行:if($.inArray(this.id, savedInternal) !== -1) { console.log("yes"); } else { console.log("no"); }这是在鼠标悬停在元素上时发生的,如果我放置以下内容id是正确的,那么它不是关于this.idconsole.log(this.id);我明白了128545,这是正确的。完整代码:google.maps.event.addListener(circle, 'mouseover', function(e) { <?php $user_id = get_current_user_id(); $userPostsInternal = get_user_meta( $user_id, 'save_post_internal', TRUE ); $userPostsExternal = get_user_meta( $user_id, 'save_post_external', TRUE ) ?> var savedInternal = "<?php echo $userPostsInternal; ?>"; var savedExternal = "<?php echo $userPostsExternal; ?>"; savedInternal = savedInternal.split(','); savedExternal = savedExternal.split(','); $("#timeSearch").removeClass("fadeIn").addClass("fadeOut"); $(".infoBox").removeClass("fadeOut").addClass("fadeIn"); if(this.currSite == "curr" ) { var linkGo = this.linkToPost; var whatSite = this.currSite; if($.inArray(this.id, savedInternal) !== -1) { } } infoWindow = new google.maps.InfoWindow({content: contentString}); infoWindow.setPosition(this.getCenter()); infoWindow.open(map); btnBoxSave(infoWindow, whatSite);});
1 回答
互换的青春
TA贡献1797条经验 获得超6个赞
$.inArray(...)
使用严格的比较。从您发布的代码来看,数组似乎包含字符串(它们是使用.split(...)
它创建的,返回一个字符串数组),而您要检查它是否在数组中的值 ( this.id
) 是一个数字。
要解决这个问题,请使用:
$.inArray(this.id.toString(), savedInternal)
和 $.inArray(this.id.toString(), savedExternal)
- 1 回答
- 0 关注
- 156 浏览
添加回答
举报
0/150
提交
取消