2016-06-21 46 views
0

我正在从数据库中检索图片,并希望它们在点击事件中更改。图片在点击时没有变化

上单击事件:含

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.chnj').onclick(function() { 
      $('#rotatetest').toggle(); 
     }); 
    }); 
</script> 

格图片:

<div class="col-md-12" id="rotatetest"> 

    <asp:Repeater ID="rptrTest" runat="server"> 
    <ItemTemplate> 
     <div class="col-md-9 col-md-push2 test" style="margin-top:50px;"> 
     <img class=" image img-circle" height="200" width="200" src="<%# Eval(" PhotoPath") 
      %>" style="border:10px solid white;" id="img" /> 
     </div> 
    </ItemTemplate> 
    </asp:Repeater> 

    <div style="margin-top:50px;text-align:left;"> 
    <h3 style="color:white;font-family:Pristina;"> 
     <%# Eval("Description") %> 
    </h3> 
    </div> 
</div> 

的onclick应被点击span元素上课chnj内glyphicon时触发。

+0

请问您可以添加更多信息。 – miny1997

+3

您的点击方法不是有效的jQuery方法,请尝试使用'.on()'或'.click()'。并且以面值为函数,只要点击触发元素,就会切换'#rotatetest'的可见性 – UncaughtTypeError

+0

我想你会希望使用click()而不是onclick:https:// api.jquery.com/click/ – user1934587390

回答

3

有没有onclick事件jQuery的,它应该是click

$('.chnj').click(function() { 
    $('#rotatetest').toggle(); 
}); 

你也可以使用事件委派on()

$('body').on('click', '.chnj', function() { 
    $('#rotatetest').toggle(); 
}); 

onclick可以作为内联事件:

<button onclick="myFunction()">Click me</button> 

或在香草中js:

myElement.onclick=function(){ myScript }; 

希望这会有所帮助。

0

在jQuery中,你需要使用.click,并为多个事件,您可以使用on而不是"onclick"。因为onclick在JavaScript代码中使用。

+0

切换功能不会在点击事件中更改图像,而是会产生模糊效果。我需要更改onclick事件中的图像。我尝试更改src属性,但这不是一个可行的选项动态 –

+0

可能是此链接帮助你:http://stackoverflow.com/questions/12355799/changing-image-on-jquery-toggle-function –

+0

如果我想要什么在jQuery中使用src属性更改图像。这段代码有什么问题? –