在jquery中使用click时无法更改css
我有一个小演示:
<div class="box_content_height">
<strong>Height: </strong>
<input type="text" name="height" id="height" value="300" />px
<input type="submit" class="submit_advance" value="submit" />
</div>
当我输入 input = 500 时,javascript
$('.submit_advance').click(function() {
var height_css = $('#height').val();
$('ul.nav-scroll').css('max-height', height_css+'px');
});
结果是 css 没有变化 500 结果如何是
.ul.nav-scroll {
max-height: valueofinput+px
}
I have a small demo:
<div class="box_content_height">
<strong>Height: </strong>
<input type="text" name="height" id="height" value="300" />px
<input type="submit" class="submit_advance" value="submit" />
</div>
And javascript
$('.submit_advance').click(function() {
var height_css = $('#height').val();
$('ul.nav-scroll').css('max-height', height_css+'px');
});
When I type input = 500 is result css no change 500
How to result is
.ul.nav-scroll {
max-height: valueofinput+px
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
改变这个:
change this :
您的
提交
可能会导致页面因提交表单而重新加载,从而撤消您的更改。如果您不希望发生这种情况,请将return false
添加到处理程序的末尾。Your
submit
may be causing the page to reload due to the form being submitted, undoing your changes. If you don't want this to happen, add areturn false
to the end of your handler.这是一个错字吗?你的 css 定义有一个“.”在 ul 前面:
你的 javascript 选择器与上面的不对应:
你的 css 应该是:
is this a typo? Your css definition has a "." in front of ul:
your javascript selector does not correspond with the above:
Your css should be: