jquery - 摇动事件以显示必填字段的表单字段?

标签 jquery html css validation

好的,所以我有这个表单,我用 onclick 事件验证它并在更改时提交

<form action="reservation.php" method="post">
                             <input class="date" id="from" name="from" type="text" value="<?php echo $from; ?>" onclick="document.getElementById('to').removeAttribute('disabled')" >   
                             <h5>Checkout</h5>
                             <input class="date" id="to" name="to" type="text" value="<?php echo $to; ?>" disabled onclick="document.getElementById('room_type').removeAttribute('disabled')">
                             <h5>Room</h5>
                             <select id="room_type" name="room_type" class="frm-field required" onChange='this.form.submit()' disabled>
                               <option value="" selected="selected" disabled="disabled">Select</option>
                                    <option value="Delux">Deluxe Rooms</option>       
                                    <option value="Executive">Executive Rooms</option>
                                    <option value="Suite">Suites</option>
                              </select>
                              <noscript><input type="submit" name="submit" value="Check"/></noscript>
                              </form>   

假设有人试图立即点击房间选择字段,然后 Checkin 和 Checkout 字段出现红色边框,如果有人已经为 Checkin 字段选择了值但没有尝试点击 Checkout 并再次尝试去选择字段,然后只有结帐字段带有红色边框,让用户知道这是必填字段?

希望有人能帮助实现这一目标,我们将不胜感激。

最佳答案

$( document ).click(function() {
  $( "#toggle" ).effect( "shake" );
});
#toggle {
    width: 100px;
    height: 100px;
    background: #ccc;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>shake demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
 
<p>Click anywhere to shake the box.</p>
<div id="toggle"></div>
 

</body>
</html>

在使用 jqueryui 的点击事件中,您可以使用 shake effect

$( "#to").effect( "shake").css( "border", "2px solid red");

编辑

另一种使用 animation css 的解决方案:-

<button id="shakebtn">shake</button>
<input class="date" id="to" name="to" type="text" value="<?php echo $to; ?>" disabled onclick="document.getElementById('room_type').removeAttribute('disabled')">

<script type="text/javascript">
    $('#shakebtn').click(function(){
       $('#to').removeClass().addClass('animated shake borderred').one('webkitAnimationEnd oAnimationEnd', function(){
            $(this).removeClass();
       });
    });
</script>

css 会是

.borderred {
    border:2px solid red
}

EDIT as per your comment i have added a demo from here please go through for very basic configuration with js to fit in your code.

关于jquery - 摇动事件以显示必填字段的表单字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35946401/

相关文章:

javascript - Formspree (HTML) 和 JavaScript 不能同时工作。 ( toast 图书馆)

jquery - 帮助解决第一个 Greasemoney 脚本问题

javascript - 检查是否未选择空 <option> 的最佳方法(使用 jQuery)

javascript - 需要帮助将 appendChild 更改为 replaceChild

python - Django模板-p标签无故关闭

html - Div溢出而不是单独的行

javascript - jqplot 条形图刻度线聚集在一起

php - 如何通过同时提供 INDEX 将值分配给 JSON

html - 看不懂背景位置的语法?

javascript - 使用 javascript for 循环在一个网页中创建 100 个小型 Iframe