简体   繁体   English

点击功能在javascript中不起作用

[英]click function is not working in javascript

I have a modal for signup and signin . 我有一个signupsignin In signup modal when I click to signin button then signup modal will hide and signin modal will appear. 在单击signin按钮时signup模式,然后signup模式将隐藏,并且将出现signin模式。 From same procedure happen to signin modal. 从相同的程序发生signin模式。

But here these signin or signup button inside the modal didn't work. 但是这里模态中的这些signinsignup按钮不起作用。

I didn't find out the script problem since I am not good in JS. 因为我不善于JS,所以我没有发现脚本问题。

Here is the modal 这是模态

<form class="form-horizontal" id="signin_form">
                                        <input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
                                        <fieldset>
                                        <!-- Sign In Form -->

                                        <!-- Email input-->
                                        <div class="control-group">
                                          <div class="controls">
                                            <input required="" id="signin_email" name="email" class="col-ld-12 col-md-12 col-sm-12" type="email" placeholder="Email" class="input-medium">
                                          </div>
                                        </div>

                                        <div class="control-group">
                                          <div class="controls">
                                            <input required="" id="signin_password" name="password" class="col-ld-12 col-md-12 col-sm-12" type="password" placeholder="Password" class="input-medium">
                                          </div>
                                        </div>

                                        <!-- Button -->
                                        <div class="control-group">
                                          <div class="controls modal_submit_button">
                                            <button type="button" class="btn btn-success" id="signin_form_submit_button">Sign In</button>
                                          </div>
                                        </div>

                                         <div class="control-group">
                                          <div class="controls modal_submit_button">
                                            Don't have an account ! Click here to 
                                            <a href="#" class="signup_from_signin_modal">Sign Up</a>
                                          </div>
                                        </div>
                                        </fieldset>
                                    </form>

script 脚本

$(document).ready(function(){
$('.signup_from_signin_modal').on("click", function() {
  $('#signin_Modal').modal('hide');
  $('#myModal').modal('show');
});
$('.signin_from_signup_modal').on("click", function() {
  $('#myModal').modal('hide');
  $('#signin_Modal').modal('show');
});
});

Further more no error is shown into console . 此外, console不会显示任何错误。

Anybody help please? 有人帮忙吗? Thanks in advance 提前致谢

First of all in the handler function of the click you should prevent the default action of the <a> tag. 首先,在click的处理函数中,您应该阻止<a>标记的默认操作。 Like so: 像这样:

  $(document).ready(function(){
   $('.signup_from_signin_modal').on("click", function(e) {
   e.preventDefault();
   $('#signin_Modal').modal('hide');
   $('#myModal').modal('show');
  });

Please let me know if this helps and apply this principle to other HTML tags that already have a default event associated. 如果这有帮助,请告诉我并将此原则应用于已经关联了默认事件的其他HTML标记。 Like forms with button of type submit for instance. 比如提交类型按钮的表格。 Don't forget to prevent this default event so that you can use your specified event. 不要忘记阻止此默认事件,以便您可以使用指定的事件。 Hope this helps. 希望这可以帮助。

There are missing places in the code. 代码中缺少位置。 That's why I didn't understand the problem. 这就是为什么我不明白这个问题。 Can you try that? 你能试试吗?

  $(document).ready(function(){

$('.signup_from_signin_modal').click(function(e) {
  e.preventDefault()
  $('#signin_Modal').hide();
  $('#myModal').show()
})
  });

Where is #myModal ? #myModal在哪里?

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

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