我在过去几个月里开发的预订模块有问题。您可以在以下地址查看:


 

除了一个问题,一切都很完美。当我减小浏览器窗口的大小时,我决定使图像消失并仅保留预留模块。调整大小后,它将停止工作:所有脚本功能(根据出发选择和“获取价格”按钮提供到达的功能)不起作用。你能告诉我导致这个问题的原因吗?


下面你可以找到代码中你可能会发现问题的主要部分。
&#xA ;
HOMEPAGE


 < body>&# XA;< PHP
 $ explode = explode('/',$ _SERVER ['REQUEST_URI']);
 if($ explode [1] =='it'和$ explode [2] =='ros-ncc'){
?>
< div id =“image”>&# XA; < div id =“modulemax”>
 < PHP
要求( '可湿性粉剂内容/主题/ customizr / prenota / index.php的');
?>
 < / DIV>
< / DIV>
< PHP
 } else if($ explode [1] ==''和$ explode [2] ==''){
?>
< div id =“image”>
 < div id =“modulemax”>
<?php
 require('wp-content / themes / customizr / book / index.php');
?>&# XA; < / div>
< / div>
<?php
} else {
 }
 ?>
< div id =“modulemin”>
 < PHP
 $ explode = explode('/',$ _SERVER ['REQUEST_URI']);
 if($ explode [1] =='it'和$ explode [2] =='ros-ncc'){
要求( '可湿性粉剂内容/主题/ customizr / prenota / index.php的');
 } else if($ explode [1] ==''和$ explode [2] ==''){
需要( '的wp-content /主题/ customizr /电子书/的index.php');
 } else {
}
?>
< / div>
< / body>


& #xA; INDEX - BOOK(英语预订模块)


 <?php include“prova1。 PHP的“; ?>
< script>
 function getArrival(val){
 $ .ajax({
 type:“POST”,
 url:“wp-content / themes / customizr / book / process.php”,
 data:'dep_name ='+ val, 
成功:功能(数据){
 $(“#arrivals-list”)。html(数据);
}
});
}&#xA ;< / script>
< script>
 function chk(){
 var var1 = document.getElementById('departures-list')。value;
 var var2 = document.getElementById('arrivals-list')。value;
 var var3 = document.getElementById('passengers')。value;
 var var4 = document.getElementById('bags')。value;
 var dataString ='var1 ='+ var1 +'& var2 ='+ var2 +'& var3 ='+ var3 +'& var4 ='+ var4;
 $ .ajax({
 type:“POST”,
 url:“wp-content / themes / customizr / book / process2.php”,
 data:dataString,
 cache :false,
 success:function(html){
 $('#resbox')。html(html);
}
});
返回false;
}
< / script>
< body>
< div id =“rcorners1”>
 < form action ='wp-content / themes / customizr / book / index.php'methodal ='post'>
 <标签>出发:其中/标签>
 < select name =“departures”id =“departures-list”class =“form-control”onchange =“getArrival(this.value);”>
 < option value =“”>选择离开< / option>
 < PHP
需要( '的wp-content /主题/ customizr /电子书/ prova1.php');
 $ sql1 =“SELECT * FROM departures”; 
 $ result1 = $ mysqli-> query($ sql1);
 while($ row1 = $ result1-> fetch_assoc()){
 ?> 
 < option value =“<?php echo $ row1 [”dep_name“];?> |<?php echo $ row1 [”dep_air“];?>”><?php echo $ row1 [ “dep_name”]; ?>< /选项>
 <?php}?>
 < /选择>
 <标签>抵达:其中/标签>
 < select id =“arrivals-list”name =“arrivals”>
 < option value =“”>选择到达< /选项>
 < / select>
< input id =“input”type =“submit”name =“submit”onclick =“return chk()”value =“Get Price”/>
< /形式>
 代码>


答案 0 :(得分:0)
您的网站中有两个不同的div
。其中一个有id = image
,第二个是id = modulemin
。当id = image
使用css(screen size < 800px width
)时隐藏display = none
,而第二个隐藏screen size > 799px width
时使用css(display = none
)。它们都有类似的形式。你为什么需要它?为什么只有不同屏幕尺寸的2种相似形式?
您的主要问题在于id's
变量form inputs
var1, var2 ...
。
您尝试使用ids
inputs
获取一些信息:
var var1=document.getElementById('departures-list').value;
但是,正如您所理解的那样,您始终只会从inputs
中的第一个表单获得DOM tree
,因为在找到任何id
,js
停止搜索的第一次出现后并返回它。您可以在任何js
文档中找到更详细的信息。
您可以使用class
代替id
从页面获取具有相同类名的所有inputs
。您可以对表单使用一些不同的id
,然后将inputs
与id/name/class/tagname
作为该表单ex.的子node
获取。
另外,强烈建议不要将ajax
请求发送到其他文件。而不是它,使用wp-ajax。