[英]Jquery: change css selector on click
I just get {"error": "Please use POST request"} when I run this 运行此命令时,我刚收到{“ error”:“请使用POST请求”}
$("#ricomporreclick").click(function () {
$("#film").css('visibility', 'hidden');
$("#ricomporre").css('visibility', 'visible');
});
What's wrong with the code? 代码有什么问题? I'm tring to change the selector without page being reloaded.. when the click is triggered #film should be display:none and #ricomporre should be visible.
我正在尝试在不重新加载页面的情况下更改选择器..触发单击时,应该显示#film:none和#ricomporre应该是可见的。
just put return false
at end of the code block. 只需将
return false
放在代码块的末尾。
You need to stop the link from redirecting by using the preventDefault method. 您需要使用preventDefault方法停止链接的重定向。 I've edited the fiddle to show this
我已经编辑了小提琴以显示此内容
$("#ricomporreclick").click(function (e) {
$("#film").css('visibility', 'hidden');
$("#ricomporre").css('visibility', 'visible');
e.preventDefault();
});
What was happening previously was that it was correctly changing the visibility, but then the link was reloading the page causing the css to be reset to the stylesheet. 以前发生的事情是它正确地更改了可见性,但是随后该链接重新加载了页面,从而导致css重置为样式表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.