admin管理员组文章数量:1389754
This is my test code:
describe("Login", function(){
beforeEach(function(){
loadFixtures('login-fixture.html');
})
it("should enable the button when checking 'remember password'", function(){
$('#remember').trigger('click');
expect($('#keepIn')).not.toBeDisabled();
});
});
And this is my production code:
$(document).ready(function(){
$('#remember').click(function(e) {
if($('#remember').is(':checked'))
{
$('#keepIn').removeAttr('disabled');
}
});
});
This is not working, the production code never gets called. I have put alerts before and after the trigger event and after the trigger the checkbox is checked, but the .click function does not get called.
Any thoughts on why is this happening?
This is my test code:
describe("Login", function(){
beforeEach(function(){
loadFixtures('login-fixture.html');
})
it("should enable the button when checking 'remember password'", function(){
$('#remember').trigger('click');
expect($('#keepIn')).not.toBeDisabled();
});
});
And this is my production code:
$(document).ready(function(){
$('#remember').click(function(e) {
if($('#remember').is(':checked'))
{
$('#keepIn').removeAttr('disabled');
}
});
});
This is not working, the production code never gets called. I have put alerts before and after the trigger event and after the trigger the checkbox is checked, but the .click function does not get called.
Any thoughts on why is this happening?
Share Improve this question edited Jun 25, 2012 at 15:17 mornaner asked Jun 25, 2012 at 15:09 mornanermornaner 2,4242 gold badges28 silver badges39 bronze badges 4- Where does that ".checkboxradio" thing e from? – Pointy Commented Jun 25, 2012 at 15:18
- what errors are thrown in console? – charlietfl Commented Jun 25, 2012 at 15:20
- @Pointy It's jQuery-mobile. Anyways i've changed the code to do it just with jQuery – mornaner Commented Jun 25, 2012 at 15:21
- @charlietfl No errors in console just the test doesn't pass. I've seen that doesn't get called debugging it with firebug – mornaner Commented Jun 25, 2012 at 15:23
1 Answer
Reset to default 6Without seeing the rest of the code, I'm assuming the "login-fixture.html" contains the "#remember" checkbox. If so, it's loading after the DOM loads. Meaning that the 'click' event you want assigned will only apply to previously loaded elements. The jQuery on() event will assign any event you want to newly loaded elements. You might want to try adding a on() event to that id. Something like:
$(function(){
$('#remember').on('click', function(){
if($('#remember').is(':checked')){
$('#keepIn').checkboxradio('enable');
}
});
});
Hope that helps.
See: http://api.jquery./on/
本文标签: javascriptjQuery trigger(39click39) not working with JasminejqueryStack Overflow
版权声明:本文标题:javascript - jQuery trigger('click') not working with Jasmine-jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744691172a2620002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论