缩小屏幕尺寸时,<script>功能不起作用

时间:2018-01-14 21:23:24

标签: javascript php wordpress

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

&#xA;&#xA;

出租车米兰

&#xA;&#xA;

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

&#xA;&#xA;

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

&#xA ;&#xA;

HOMEPAGE

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

INDEX - BOOK(英语预订模块)

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

1 个答案:

答案 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,因为在找到任何idjs停止搜索的第一次出现后并返回它。您可以在任何js文档中找到更详细的信息。

您可以使用class代替id从页面获取具有相同类名的所有inputs。您可以对表单使用一些不同的id,然后将inputsid/name/class/tagname作为该表单ex.的子node获取。

另外,强烈建议不要将ajax请求发送到其他文件。而不是它,使用wp-ajax