2013-02-25 36 views
0

她是我的html:如何获取与jquery标签

<div class="product-img-box"> 
    <p class="product-image product-image-zoom"> 
     <a href='http://placehold.it/700x600' class='cloud-zoom' id='aMainImageZoom' rel="adjustX: 10, adjustY:-4"> 
      <asp:Image Style="max-height: 400px; width: 400px;" ImageUrl="http://placehold.it/300x350" 
       runat="server" ID="imgProductImageLarge" /> 
     </a> 
    </p> 
    <div class="more-views"> 
     <div class=" jcarousel-skin-tango"> 
      <ul id="more_view"> 
       <li><a href='' class='cloud-zoom-gallery' title='Thumbnail 1' 
        rel="useZoom: 'zoom1', smallImage: './images/zoom2.jpg' "> 
        <asp:Image Style="max-height: 92px; width: 92px;" ImageUrl="http://placehold.it/300x351" 
         ID="imgFirst" runat="server" onmouseover='changeImage("thImg5");' /></a></li> 
      </ul> 
     </div> 
    </div> 
</div> 

,这里是我的脚本代码:

<link href="css/cloud-zoom.css" rel="stylesheet" type="text/css" /> 
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script> 
<script src="js/cloud-zoom.1.0.2.js" type="text/javascript"></script> 
$(document).ready(function() { 
     $(function() { 
      $("#imgFirst").on("mouseenter", function() { 
       $("#<%=imgProductImageLarge.ClientID %>").attr("src", this.src); 
       $("#aMainImageZoom").attr("href", "http://placehold.it/700x602"); 
      }); 
     }); 
    }); 
</script> 

这里是我的HTML视图来源:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title> 

</title><link href="css/cloud-zoom.css" rel="stylesheet" type="text/css" /> 
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script> 
    <script src="js/cloud-zoom.1.0.2.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $(function() { 
       $("#imgFirst").on("mouseenter", function() { 
        $("#imgProductImageLarge").attr("src", this.src); 
        $("#aMainImageZoom").attr("href", "http://placehold.it/700x602e"); 
       }); 
      }); 
     }); 

    </script> 
</head> 
<body> 
    <form method="post" action="WebForm1.aspx" id="form1"> 
<div class="aspNetHidden"> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTUwNjA3NTE5MmRkpBlwGdNLH5SqyoT+HpJkrN3Qg3IyiI4/4Nchrs2wg+g=" /> 
</div> 

    <div class="product-img-box"> 
     <p class="product-image product-image-zoom"> 
      <a href='http://placehold.it/700x600' class='cloud-zoom' id='aMainImageZoom' rel="adjustX: 10, adjustY:-4"> 
       <img id="imgProductImageLarge" class="mainImage" src="http://placehold.it/300x350" style="max-height: 400px; width: 400px;" /> 
      </a> 
     </p> 
     <div class="more-views"> 
      <div class=" jcarousel-skin-tango"> 
       <ul id="more_view"> 
        <li><a href='' class='cloud-zoom-gallery' title='Thumbnail 1' rel="useZoom: 'zoom1', smallImage: './images/zoom2.jpg' "> 
         <img id="imgFirst" src="http://placehold.it/300x351" style="max-height: 92px; width: 92px;" /></a></li> 
       </ul> 
      </div> 
     </div> 
    </div> 
    </form> 
</body> 
</html> 

我想要改变aMainImageZoom href aMainImageZoom在imgFirst的鼠标悬停上。但我无法获得一个主要的图像缩放。你有什么主意吗?

+4

这可能是明智的,把你的js代码的的document.ready功能不能使用jQuery – 2013-02-25 09:29:58

+1

并使用jQuery来实际完成这项工作 – mplungjan 2013-02-25 09:31:07

+2

@ChetterHummin如果只使用函数需要在document.ready中?因为那个时候你不一定需要它? – 2013-02-25 09:35:11

回答

0

你可以试试下面

$(document).ready(function(){ 

    $('#imgProductImageLarge').mouseenter(function(){ 

    $(this).parent("a").attr("href","new-val"); 
    return false; 
    }); 

}); 
+0

I想要在第一个p标记中更改href而不是在more-views div中。 – cagin 2013-02-25 10:01:38

+0

@cagin,已更新回答 – 2013-02-25 10:05:32

+0

正如您在我的问题中所看到的,我想先更改imgFirst的鼠标悬停的href。我只想做缩放。 – cagin 2013-02-25 10:10:28

1

这是为什么,因为你加载

DEMO

$(function() { 
    $("#imgFirst").on("mouseenter",function() { 
     $("#<%=imgProductImageLarge.ClientID %>").attr("src",this.src); 
     $("#aMainImageZoom").attr("href","some other value"); 
    }); 
}); 
+0

你是对的,但我的问题不在那里。 – cagin 2013-02-25 10:00:32

+0

卡金,我认为这是你需要的。从我的回答评论我明白。让我们知道 – 2013-02-25 10:13:23

+0

$(document).ready(function(){(function(){(“#imgFirst”)。on(“mouseenter”,function(){alert('come in'); (“#<%= imgProductImageLarge.ClientID%>”)。attr(“src”,this.src); }); }); }); 我改变了我的代码,但没有提示?任何建议? – cagin 2013-02-25 10:27:33