第二次点击时,jquery中没有函数错误

时间:2014-12-26 03:53:04

标签: javascript php jquery html css

我在wordpress插件中遇到问题。我制作了一张位于该位置的图像区域地图。

http://singhalcompetitionclasses.com/newspaper/

在这里我创建了两个区域地图。

当我第一次点击任何区域地图时,它会显示弹出

但是当我再次点击任何区域地图时,它会在控制台

中出错

hello is not a function

我使用的代码如下:

<script>
function hello(id){ 
        var path = "<?php echo $path; ?>";
        alert(id);
        var path = path+id+'/'+id+'.jpg';
        image = "<img src='"+path+"' id='hello'>";
        //alert(image);
        jQuery("#hidden").html(image);
         var newwindow = window.open(jQuery(this).prop('href'), '', 'height=800,width=800');
       // if (window.focus) {
            newwindow.focus();
            newwindow.document.write( jQuery("#hidden").html() );
        //}
        return false;
    }
</script>

<div style="width: 900px; overflow: scroll; float: left;">
<img src="<?php echo $img_src;?>" id="photo" style="width: 850px;" usemap="#planetmap" />
</div>
<map name="planetmap">
<?php
$sql = mysql_query("select * from epaper");
while($row = mysql_fetch_array($sql)){
    $xx = $row['file_id'];
    echo '<area shape="rect" style="cursor:pointer;" coords="'.$row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2'].'" target="_blank" onclick="return hello('.$xx.');" alt="Sun" onmouseover="borderit(this,"black")" onmouseout="borderit(this,"white")">';
}
?>
<div id="hidden" style="display:none;">

</div>
</map>

请大家帮我解决问题

2 个答案:

答案 0 :(得分:1)

I have checked the coded there is string error you can use below code:
I hope this is fine for you:-

while($row = mysql_fetch_array($sql)){
    $xx = $row['file_id'];
    ?>
        <area shape="rect" style="cursor:pointer;" coords="<?php echo $row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2']; ?>" target="_blank" onclick="return hello('<?php echo $xx; ?>');" alt="Sun" onmouseover="borderit(this,'black')" onmouseout="borderit(this,'white')">
    <?php   }  ?>

OR

echo '<area shape="rect" style="cursor:pointer;" coords="'.$row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2'].'" target="_blank" onclick="return hello('.$xx.');" alt="Sun" onmouseover="borderit(this,\'black\')" onmouseout="borderit(this,\'white\')">'; 

答案 1 :(得分:1)

您的函数名称用作其中html元素的id。它使浏览器感到困惑。

更改此行的ID:

image = "<img src='"+path+"' id='hello'>";

到(示例):

image = "<img src='"+path+"' id='other_id'>";