带有两个 Id 的 PHP div

我有一个页面,您可以在其中添加产品、零件、材料和包装。当在产品上选择排序 (pm_sort) 时,它应该显示产品信息,但当选择部分时,它也应该显示产品信息。我得到以下代码:


<select required  class='selectpicker form-control border' name='pm_sort' id='pm_sort' value="<?php echo isset($_POST['pm_sort']) ? htmlspecialchars($_POST['pm_sort'], ENT_QUOTES) : "";  ?>">

               <option selected="true" disabled="disabled" value="">Select sort...</option>

                   <option>Product</option>

                   <option>Material</option>

                   <option>Part</option>

                   <option>Packaging</option>        

           </select>


<div class='Product' id='Product' || id='Part'>

   <h3>Product information</h3>

<input type='text' name='pm_code' class='form-control' value="<?php echo isset($_POST['pm_code']) ? htmlspecialchars($_POST['pm_code'], ENT_QUOTES) : "";  ?>" />

</div>


<div class='material' id='material'>

   <h3>Material information</h3>

<input type='text' name='pm_code_m' class='form-control' value="<?php echo isset($_POST['pm_code_m']) ? htmlspecialchars($_POST['pm_code_m'], ENT_QUOTES) : "";  ?>" />

</div>


<div class='Packaging' id='Packaging'>

   <h3>Material information</h3>

<input type='text' name='pm_code_p' class='form-control' value="<?php echo isset($_POST['pm_code_p']) ? htmlspecialchars($_POST['pm_code_p'], ENT_QUOTES) : "";  ?>" />

</div>



<script type='text/javascript'>

$('div').hide()


$('#pm_sort').change(function () {

     var value = this.value;

   $('div').hide()

   $('#' + this.value).show();

});

</script>


问题是:如何根据select value Part或Product得到相同的页面信息?


猛跑小猪
浏览 119回答 1
1回答

ABOUTYOU

您可以添加一个 if 语句来检查值 select 是否命名为 part 然后仍然显示产品信息:<select required&nbsp; class='selectpicker form-control border' name='pm_sort' id='pm_sort' value="<?php echo isset($_POST['pm_sort']) ? htmlspecialchars($_POST['pm_sort'], ENT_QUOTES) : "";&nbsp; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option selected="true" disabled="disabled" value="">Select sort...</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option>Product</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option>Material</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option>Part</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option>Packaging</option>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</select><div class='Product' id='Product' || id='Part'>&nbsp; &nbsp;<h3>Product information</h3><input type='text' name='pm_code' class='form-control' value="<?php echo isset($_POST['pm_code']) ? htmlspecialchars($_POST['pm_code'], ENT_QUOTES) : "";&nbsp; ?>" /></div><div class='material' id='material'>&nbsp; &nbsp;<h3>Material information</h3><input type='text' name='pm_code_m' class='form-control' value="<?php echo isset($_POST['pm_code_m']) ? htmlspecialchars($_POST['pm_code_m'], ENT_QUOTES) : "";&nbsp; ?>" /></div><div class='Packaging' id='Packaging'>&nbsp; &nbsp;<h3>Material information</h3><input type='text' name='pm_code_p' class='form-control' value="<?php echo isset($_POST['pm_code_p']) ? htmlspecialchars($_POST['pm_code_p'], ENT_QUOTES) : "";&nbsp; ?>" /></div><script type='text/javascript'>$('div').hide()$('#pm_sort').change(function () {&nbsp; &nbsp; &nbsp;var value = this.value;&nbsp; &nbsp;$('div').hide()&nbsp; &nbsp;if(value == "Part"){&nbsp; &nbsp; &nbsp; &nbsp;$('#Product').show();&nbsp; &nbsp;}else{&nbsp; &nbsp; &nbsp; &nbsp;$('#' + value).show();&nbsp; &nbsp;}});</script>
打开App,查看更多内容
随时随地看视频慕课网APP