奇怪的行为JS - 立即工作时间 [英] Strange behavior JS - works times at once

查看:100
本文介绍了奇怪的行为JS - 立即工作时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

祝你好运!

需要你的意见......



页面连接了脚本js。未检测到调试器中的错误。

在产品的详细信息页面上有一个book按钮,该按钮最初处于非活动状态。

进入此页面之后复选框,函数工作js,这使得活动按钮提交表单。

点击按钮 - 功能工作AJAX。

问题是再次工作通过AJAX和活动按钮 - 没有错误。

这是什么废话,甚至不知道在哪里挖,以及如何在大海捞针中找到这个针。

谢谢!

< script type =text / javascriptsrc =my.js>< / script> 



使用我的js代码在页面my.js文件中找到:



 $( function (){

$(' #search_result')。dblclick( function (){
$( this )。隐藏();

});
$( #search input [type = submit])。click( function (){
$ .ajax({
url: / engine / controller / search.php
类型: POST
dataType:' json'
data:{id:$( input [name = search_word])。val()},
成功:功能(结果){
GetSearchResult(result);
}
});
返回 false ;
});

$( input [name = tos])。click( function (){
var checked_status = this .checked;
if (checked_status == true ){
$( 。tos .but)。removeAttr( disabled)。addClass(' but_active');
} else {
$( 。tos .but)。attr( 已禁用 disabled)。removeClass( <跨度类= 代码串> but_active');
}
});


$( #rez)。click( function (){

var email = $( #mail)。val();
var name = $( #name)。val();
var phone = $( #phone) .val();
var info = $( #info)。val();
var id = $( #id)。val();

$ .ajax({
type:' POST'
url:' <跨班=code-string> / rezervation.php'

dataType:' json'
数据:' email =' + email + ' & name =' + name + ' & phone =' + phone + ' & info =' + info + ' & id =' + id,
成功: function (data){
var block = ' #mes';
if (data.statuse == 1 ){block = ' '; $(' .tos table')。hide();}
$(' .tos' + block).html(' ' + data.message [ 0 ] + ' ');

}
});
});

function GetSearchResult(result){

var html = ' ';
if (result.message == undefined ){
html = ' ID:' + result [ 4 ]。 val + ' ' + result [ 1 ] .val + ' ' +结果[ 5 ] .val + ' €';
} else {
html = ' ' + result.message + ' ';
}

$( #search_result div)。 HTML(HTML);
$( #search_result)。show();
}

function validateEmail(email){
var re = /^(([^<>()[\\\.,;:\\\@\ < span class =code-string>] +(\。[^<>()[\] \\。,;:\ s @ \] +)*)|(\\ \\ + \))@((\ [[0-9] {1,3} \。[0-9] {1,3} \。[0-9] {1,3 } \ [0-9] {1,3} \])|(([A-ZA-Z\-0-9] + \)+ [A-ZA-Z] {2, }))$ /;
return re.test(email);
}

函数validate(){

var email = $( #email )。val();
$(
#email )。css('border','auto') ;
if(!validateEmail(email)){

alert('Email is not correct');
$(
#email )。css('border','1px solid red );
$(
#email )。val('');
//$(\"
.tos。但 )。attr( disabled 已禁用 < span class =code-string>)。removeClass('but_active');

}
返回false;
}

});







这是HTML:



< label> 
< input type =checkboxname =tosvalue =1>我阅读了条款和条件
< / input>< / label>







名称
< input type =textclass =field id =namename =data [name]>


电子邮件
< input id =emailtype =textonblur =validate(); class =fieldname =data [mail]>


Telefon
< input type =textclass =fieldid =phonename =data [phone]>


信息

< textarea class =textfieldid =infoname =data [info]>< / textarea>





< input type =hiddenname =idid =idvalue =40>
预订





< input type =hiddenname =acvalue =send_msg>< ; /输入>< /输入>< /输入>< /输入>< /输入>

解决方案

function (){

' #search_result')。dblclick( function (){


this )。hide();

});


Good luck!
Need your opinion ...

A page has connected scripts js. Errors in the debugger is not detected.
On the details page of the product there is a button "book", which is initially inactive.
In going to this page after the checkbox, function works js, which makes the active button to submit the form.
By clicking on the button - function works AJAX.
The problem is that once again works through AJAX and activity buttons - with no errors.
What nonsense is this, do not even know where to dig and how to find this needle in a haystack.
Thank you!

<script type="text/javascript" src="my.js"></script>


Locate at page my.js file with my js code:

$(function() {

    $('#search_result').dblclick(function() {
        $(this).hide();
   
    });
    $("#search input[type=submit]").click(function() {
    $.ajax({
      url:"/engine/controller/search.php",
      type:"POST",
      dataType: 'json',
      data: {id: $("input[name=search_word]").val()},
      success:function(result){ 
        GetSearchResult(result);
      }
    });
    return false;
    });

$("input[name=tos]").click(function() {
    var checked_status = this.checked;
    if (checked_status == true) {
       $(".tos .but").removeAttr("disabled").addClass('but_active');
    } else {
       $(".tos .but").attr("disabled", "disabled").removeClass('but_active');
    }
});

    
$("#rez").click(function() {

  var email = $("#email").val();
  var name = $("#name").val();
  var phone = $("#phone").val();
  var info = $("#info").val();
  var id = $("#id").val();

$.ajax({
  type: 'POST',
  url: '/rezervation.php',
  dataType : 'json',
  data: 'email='+email+'&name='+name+'&phone='+phone+'&info='+info+'&id='+id,
  success: function(data){
    var block = '#mes';
    if (data.statuse == 1 ) {block = ''; $('.tos table').hide();} 
      $('.tos '+block).html(''+data.message[0]+'');
 
  }
});
});

function GetSearchResult(result){

          var html ='';
          if (result.message == undefined) {
          html = 'ID: '+result[4].val+''+result[1].val+''+result[5].val+' €';
          } else {
              html = ''+result.message+'';
          }

          $("#search_result div").html(html);
          $("#search_result").show();
}

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function validate(){
  
  var email = $("#email").val();
  $("#email").css('border','auto');
  if (!validateEmail(email)) {
   
   alert('Email is not correct');
   $("#email").css('border','1px solid red');
   $("#email").val('');
   //$(".tos .but").attr("disabled", "disabled").removeClass('but_active');
   
  }
  return false;
}

});




Here is HTML:

        <label>
            <input type="checkbox" name="tos" value="1"> I read Terms and Conditions
        </input></label>







        Name
        <input type="text" class="field" id="name" name="data[name]">


        E-mail
        <input id="email" type="text" onblur="validate();" class="field" name="data[mail]">


        Telefon
        <input type="text" class="field" id="phone" name="data[phone]">


        Info

            <textarea class="textfield" id="info" name="data[info]"></textarea>





            <input type="hidden" name="id" id="id" value="40">
            Book





<input type="hidden" name="ac" value="send_msg"></input></input></input></input></input>

解决方案

(function() {


('#search_result').dblclick(function() {


(this).hide(); });


这篇关于奇怪的行为JS - 立即工作时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆