gpt4 book ai didi

javascript - 在我的案例中如何使用单选按钮选中或单击的属性

转载 作者:行者123 更新时间:2023-11-28 10:03:45 24 4
gpt4 key购买 nike

大家好,我正在使用 Rails 3.2.13。我在我的 View 文件中使用了以下脚本。如果有人点击 ownertype Other,id=group_user_id 的 div 将打开,我将最后保存这些操作。到目前为止,当我使用 f.radio_button 时一切正常。

<div class="form-group">
Owner:
<%= f.radio_button :owner_type,"Self", :id=>"self-group", :checked =>true %>
Self
<%= f.radio_button :owner_type,"Other",:id=>"other-group" %>
Others
</div>

<div id="group_user_id" class="form-group">
<span>
<%= text_field_tag "account_id", nil, :id => "autocomplete_text", :class => "form-control", :placeholder => "Account Id" %>
</span>
</div>

Javascript 代码

<script>
$(document).ready(function() {
$("#group_user_id").hide();
$("#self-group").prop("checked", true);

$("#other-group").click(function() {
$("#group_user_id").show();
});

});

现在我正在为单选按钮使用模板 css,之后它就不起作用了。以下是供您引用的代码。

在这种情况下,单选按钮类使用方形绿色单行。尽管我提供了 f.radio_button 并在其上传递了正确的 ID,但 Rails 单选按钮是隐藏的。

<div class="row">
<div class="col-sm-2">
<div class="text-green" style="margin-top: 9px; font-size: 18px;">
Owner
</div>
</div>

<div class="col-sm-2">
<div class="icheck">
<div class="square-green single-row">
<div class="radio">
<%= f.radio_button :owner_type,"Self", :id=>"self-group", :checked =>true %>
<label>Self</label>
</div>
</div>
</div>
</div>

<div class="col-sm-2">
<div class="icheck">
<div class="square-green single-row">
<div class="radio">
<%= f.radio_button :owner_type,"Other",:id=>"other-group" %>
<label>Others </label>
</div>
</div>
</div>
</div>
</div>

我使用了以下js和css。

<%= stylesheet_link_tag "css/iCheck/skins/square/green.css" %>
<%= javascript_include_tag "js/iCheck/jquery.icheck.js", "js/icheck-init.js" %>

在这种情况下,当我们使用模板中的单选按钮时,如何管理单选按钮的点击、选中和其他属性。请提供一些解决方案。

最佳答案

据我了解,您需要在 radio_button_tag 中输入类名....然后

radio_button_tag 应具有如下格式:

radio_button_tag(name, value, checked = false, options = {})

试试这个:

<%= f.radio_button :owner_type,"Self", :id=>"self-group", :checked =>true, :class=> 'class-name' %>

这将允许 class 属性

:checked=>true 表示默认情况下它将检查单选按钮。

关于javascript - 在我的案例中如何使用单选按钮选中或单击的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24626888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com