如果选择跨度/隐藏输入值为SMTH

时间:2017-03-18 22:35:24

标签: javascript jquery html

我选择了选项,我有很多输入。如果我选择“USER”选项并在选择其他选项时再次隐藏它,我需要跨越就绪输入。

[in]
even([1,2,3,4,5,6])
[out]
[2, 4, 6]

2 个答案:

答案 0 :(得分:1)



$( "#selectlist" ).change(function(event) {
  if (this.value == 1 || this.value == 2) {
    $(".form-control").show();
  } else {
    $(".form-control").hide();
  }
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="form-signup" action="admin_users.php" method="POST" id="payment-form">

                    <div class="well well-sm">
                   	<h3 class="form-signin-heading"> Create

                    <select id="selectlist" name="selectproduct" >
                        <option value="1">User</option>
                        <option value="2">Admin</option>
                        <option value="3">Smth else</option>
                        <option value="4">Smth else of else</option>

                      </select>
                      </h3>

                   	<div class="form-group">
                      <div class="col-xs-12">
                   		<input class="form-control" type="text" name="username" id="username" placeholder="İstifadəçi" value="first input" required autofocus>
    </div>
    <div> &nbsp </div>
                      <div class="col-xs-12">
                   		<input type="text" class="form-control" id="fname" name="fname" placeholder="Ad" value="second input" required>
    </div>
    <div> &nbsp </div>

    	            <input class='btn btn-primary' type='submit' name='addUser' value='Create user' />
                  </div>
                   </form>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我会使用名为from django.shortcuts import render, redirect from . models import User from django.contrib import messages # Create your views here. def index(request): return render(request, 'logReg/index.html') def register(request): viewsResponse = User.objects.add_user(request.POST) if viewsResponse['isRegistered']: request.session['user_id'] = viewsResponse['user'].id request.session['user_fname'] = viewsResponse['user'].first_name return redirect('users:success') else: for errors in viewsResponse['errors']: messages.error(request, errors) return redirect('users:index') def success(request): if 'user_id' not in request.session: messages.error(request, 'Must be logged in!') return redirect('users.index') return render(request, 'logReg/success.html') def login(request): viewsResponse = User.objects.login_user(request.POST) if viewsResponse['isLoggedIn']: request.session['user_id'] = viewsResponse['user'].id request.session['user_fname'] = viewsResponse['user'].first_name return redirect('users:success') else: for errors in viewsResponse['errors']: messages.error(request, errors) return redirect('users:index') def logout(request): return redirect('users.index') 的自定义属性。更新选择后,您的内容将自动更新。有什么不错的,你要做的就是添加另一个选项和另一个带有valueTie属性的div,然后再启动并运行另一个选项。

&#13;
&#13;
valueTie
&#13;
$("#selectlist").change(function () {
  $("[valueTie]").hide()
  $("[valueTie='" + $(this).val() + "']").show();
});

$("#selectlist").change();
&#13;
&#13;
&#13;