gpt4 book ai didi

php - 选择列表菜单回显

转载 作者:行者123 更新时间:2023-11-30 23:50:57 26 4
gpt4 key购买 nike

我有两种类型的选择列表菜单:

<select name="category">
<option>----Select----</option>
<option>Category 1</option>
<option>Category 2</option>
<option>Category 3</option>
<option>Category 4</option>
</select>

<select name="category_product">
<option>----Select----</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
</select>

我喜欢的是当我选择选择列表菜单的“类别 1”时,它与选择列表菜单“category_product”相呼应,我该怎么做?

我想把 category_product 列表菜单放在一个变量中,当我选择一个类别时,它会回显 category_products 列表菜单,但我不知道如何在选择类别时进行检测。

希望得到一些帮助

最佳答案

你唯一的方法是用 JS 或 jQuery 来做,这里是一个用 JS 做的例子,

function showProducts(cat){
document.getElementById(cat).style.display = 'block';
}

<select name="category" onchange="showProducts(this.value)">
<option>----Select----</option>
<option value="category_product">Category 1</option>
<option>Category 2</option>
<option>Category 3</option>
<option>Category 4</option>
</select>

<select style="display:none" id="category_product" name="category_product">
<option>----Select----</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
<option>Product of category 1</option>
</select>

或者如果您希望结果直接来自数据库,您必须进行 AJAX 调用的另一种选择。

更新:

用这个函数代替上面的,

function showProducts(cat){
for(var i=1;i<document.getElementsByTagName('select').length;i++){
document.getElementsByTagName('select')[i].style.display = 'none';
};
document.getElementById(cat).style.display = 'block';
}

你可以尝试一下,如果需要任何进一步的帮助,请告诉我。

关于php - 选择列表菜单回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11313129/

26 4 0