if ifel如果条件在jquery中

时间:2017-03-23 08:01:39

标签: javascript jquery

我试图隐藏并显示使用更改功能的字段,同时根据if..else if条件中的值单击单选按钮,不幸的是,它无法正常工作。如果此代码是正确的?谁能说我?提前谢谢......

Node root = session.getRootNode();
root.accept(new ItemVisitor() {
    @Override
    public void visit(Property property) throws RepositoryException {
        if (!property.isMultiple() && property.getType() == PropertyType.LONG) {
             System.out.println(property.getName() + " = " + property.getLong());
        }
    }

    @Override
    public void visit(Node node1) throws RepositoryException {
        NodeIterator children = node1.getNodes();
        while (children.hasNext()) {
            visit(children.nextNode());
        }
    }
});

jquery的

 form do |f|
   f.inputs do
   f.input :name,label:"customer name"
   f.input :service_type, as: :radio, :label => "Payment Type", :collection => [ " Bike ", " Auto " , " Car ", "Bus" ]
end
f.actions
end 

3 个答案:

答案 0 :(得分:0)

更改行

 $('#new_customer input[type=radio][name="customer[service_type]"]').change(function() {

到(我修改了jquery选择器)

 $('#new_customer input[type=radio][name^=customer]').change(function() {

答案 1 :(得分:0)

由于name是一个唯一字段,您可以使用

$('#new_customer input:radio[name="customer[service_type]"]').change(function() {

而不是

$('#new_customer input[type=radio][name="customer[service_type]"]').change(function() { 

请参阅target input by type and name (selector)

答案 2 :(得分:0)

您的代码工作正常,但选择单选按钮时,您之前选择的divs未被隐藏。为此,移动您的JS代码以隐藏divs函数中的.change(),并添加CSS以最初隐藏它们。

CSS:

#customer_two_wheel_input,
#customer_three_wheel_input,
#customer_four_wheel_input,
#customer_multiple_wheel_input{
    display: none;
}

JS:

$(document).ready(function() {

    $('#new_customer input[type=radio][name="customer[service_type]"]').change(function() {

        $('#customer_two_wheel_input').hide();
        $('#customer_three_wheel_input').hide();
        $('#customer_four_wheel_input').hide();
        $('#customer_multiple_wheel_input').hide();

        if (this.value == "Bike") {
            ..
        }
        ..
    });
});