简体   繁体   English

从onchange值显示多个div或具有相同id的表内容

[英]Display more than one div or table content of same id from onchange value

I'd like to know if you can display more than one div or table content of same id from onchange value. 我想知道您是否可以从onchange值显示多个div或具有相同id的表内容。 Like if I select an option from drop down and it displays its content but i want to display another content from elsewhere in my page when same option is selected. 就像我从下拉菜单中选择一个选项一样,它显示了其内容,但是当我选择了相同的选项时,我想从页面的其他位置显示另一个内容。

My code is as follows: 我的代码如下:

<select name="debitOrderType" id = "debitOrderType" 
onChange="display(this,'BANK','CARD','INVOICE');">
<option>Please select...</option>
<option value="BANK" selected>Debit Order (Monthly)</option>
<option value="CARD">Credit Card (Monthly)</option>
<option value="INVOICE">Invoice (Yearly)</option>
</select>

Then when selecting Invoice from dropdown it displays the following: 然后,从下拉菜单中选择发票时,将显示以下内容:

<tbody id="INVOICE" style="display: none;">
<tr>
<td class="field">Thank you for selecting to pay yearly in advance. By doing so you 
are receiving one month's free listing.
</td></tr>
</tbody>

But now i want to display the following ALSO when Invoice is selected but in another part of the page: 但是现在我想在选择发票但在页面的另一部分时显示以下ALSO:

<tbody id="INVOICE" style="display: none;">
<tr><td height="5"></td></tr>
<tr><td align="right">This is your discounted yearly price</td></tr>  
</tbody>

But only the first part is showing and not both. 但是只显示了第一部分,而不是两者都显示。 It looks like you can't display more than one content from same Id. 看来您不能显示来自同一ID的多个内容。

Hope you can help me? 希望你能帮我?

Thanks in advance! 提前致谢!

You mustn't define two elements with the same id in HTML, it's meant to be a unique identifier. 您不能在HTML中定义两个具有相同ID的元素,它是唯一的标识符。 Classes can be used multiple times, so use that! 类可以多次使用,所以使用它!

First of all it is bed practice to assign same id to more than one element, although DOM will never find 2nd element of same id. 首先,虽然DOM永远不会找到具有相同id的第二个元素,但是将相同的id分配给多个元素是一种卧床练习。 Assign class to both table and make it visible on onChange event of combo box, then it will work. 分配给两个表,并使其在组合框的onChange事件上可见,然后它将起作用。

If you want to display or apply css on single object then you should use ID . 如果要在单个对象上显示或应用CSS,则应使用ID And if you want to display or apply css on multiple object then you should use CLASS . 而且,如果要在多个对象上显示或应用CSS,则应使用CLASS

In your example you should avoid ID and use class. 在您的示例中,应避免使用ID并使用class。

avoid this 避免这个

 id="INVOICE" 

Use this 用这个

class="INVOICE"

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM