简体   繁体   English

Ruby on Rails:Jquery / ajax动态表单字段

[英]Ruby on Rails: Jquery/ajax dynamic form fields

I'm in the process of implementing dynamic form fields. 我正在实现动态表单字段。 So far, I have some jQuery that does the trick, however I have to manually refresh the page to see the change. 到目前为止,我已经完成了一些jQuery,但是我必须手动刷新页面才能看到更改。

How can I make this dynamic? 如何使它动态化? I'm under the impression I'll need to include ajax somewhere, but I'm having issues finding good resources. 我的印象是我需要在某个地方包含Ajax,但是我在寻找良好资源方面遇到了问题。

Here is the code I'm using; 这是我正在使用的代码;

jQuery ->
    $(
        if ($('#subject_enrolled').val() == '0')
            $('#subject_reason_not_enrolled').show()
        else
            $('#subject_reason_not_enrolled').hide();
    );

Any help/resources would be greatly appreciated. 任何帮助/资源将不胜感激。

I'm assuming #subject_enrolled is a checkbox. 我假设#subject_enrolled是一个复选框。 You just need to listen for the change events on that checkbox and then update the display of your #subject_reason_not_enrolled . 您只需要侦听该复选框上的更改事件,然后更新#subject_reason_not_enrolled的显示#subject_reason_not_enrolled This is covered quite a bit in other posts. 其他帖子对此进行了相当多的介绍。 Here's one: How to listen to when a checkbox is checked in Jquery 这是一个: 如何在Jquery中选中复选框时进行监听

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM