Div打开和关闭复选框 [英] Div open and close clicking checkbox

查看:63
本文介绍了Div打开和关闭复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在angularjs面临一个问题。当我选中一个复选框时,有一个动态复选框,相应的数据填充在一个正常的div中。但是,当我检查另一个复选框时,数据进入div并替换之前的div记录。这是第一个div记录替换为新的div记录。我需要单独的div记录,并有相应的复选框选中值。请帮助我吗?



我尝试过:



我在angularjs遇到问题。当我选中一个复选框时,有一个动态复选框,相应的数据填充在一个正常的div中。但是,当我检查另一个复选框时,数据进入div并替换之前的div记录。这是第一个div记录替换为新的div记录。我需要单独的div记录,那里有相应的复选框选中值。请帮助我吗?

I am facing a problem in angularjs. There have dynamic checkbox when i checked a checkbox corresponding data are populate in a div that is OK. But when i checked another check box data are come in a div and replaced the previous div record. that is first div record replace with new div record. I need individual div record with there corresponding checkbox checked value.please help me ?

What I have tried:

I am facing a problem in angularjs. There have dynamic checkbox when i checked a checkbox corresponding data are populate in a div that is OK. But when i checked another check box data are come in a div and replaced the previous div record. that is first div record replace with new div record. I need individual div record with there corresponding checkbox checked value.please help me ?

推荐答案

回到基础知识总是好的 - 也就是真正的javaScript,并学习你实际上在做什么(或者,在这种情况下,angularjs框架正在做)。



选中/取消选中复选框会导致事件发生。可以使用(处理)它来运行javaScript函数。该函数可以直接(或间接地,例如通过AJAX)用于修改页面的内容。要修改的页面上的项目(目标)将需要具有唯一的ID值。使用javaScript的DOM功能,您可以更新DIV元素的内容,通过其 唯一 ID精确选择要更新的元素。



另一个复选框也会触发事件,这也应该处理。它可以是与第一个复选框相同的事件处理程序,也可以是自己的。如果您希望使用相同的事件处理程序(高效),那么您需要将ID传递给处理程序,以便它知道选中了哪个复选框。然后,使用switch语句,您可以使用正确的文本来更新正确的DIV。



教程: JavaScript手册 [ ^ ]并在该教程中, JavaScript HTML DOM示例 [ ^ ]

It's always good to go back to basics - that is, real javaScript, and learn what it is you're actually doing (or, in this case, the angularjs framework is doing).

Checking/unchecking a checkbox causes an event. This can be used (handled) to run a javaScript function. That function directly (or indirectly, such as via AJAX) can be used to modify the content of your page. The item on the page that would be modified (the target) will need to have a unique ID value. Using the DOM functionality of javaScript, you update the contents of your DIV element, selecting exactly which one you wish to update by its unique ID.

Another checkbox would also fire an event and this should be handled as well. It could be the same event handler as the first checkbox or have its own. If you wish to use the same event handler (efficient) then you need to pass the ID to the handler so it knows which checkbox was checked. Then, using a switch statement, you can target the updating of the correct DIV with the correct text.

Tutorials: JavaScript Tutorial[^] and within that tutorial, JavaScript HTML DOM Examples[^]


这篇关于Div打开和关闭复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆