帮助javascript代码 [英] Help with javascript code

查看:101
本文介绍了帮助javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在选择某些内容时在我的代码中添加另一个输入框



如果您选择新版权声明,则在下面的jsfiddle中会出现额外的框。 />


如果从流程下拉菜单中选择纸张,我需要再添加一个盒子



可以有人帮我吗?



非常感谢任何帮助





http://jsfiddle.net/3KNnL/ [ ^ ]



谢谢

I want to add another input box into my code when something is selected

On the jsfiddle below if you select "New Claim" extra boxes appear.

I need to add a further box if "Paper" is selected from the process drop down menu

Can anyone help me please?

Any help is massively appreciated


http://jsfiddle.net/3KNnL/[^]

Thanks

推荐答案

您已经编写了代码来在Process下拉菜单下方添加输入,但是您需要检查,因为显示属性的问题是您设置为none和阻止。



首先尝试评论以下代码:

You already have written code to add input just below the Process drop-down but you need to check because problem with display property which you are setting as none and block.

First try with commenting the below code:
document.getElementById(id2).style.display = 'none';



您将在纸张选择上看到您可以看到文本框新的关税详情:。

试试吧..希望你能找到合适的解决方案。


You will see on the Paper selection you would be able to see the text box "New Tariff Details:".
just try it..hope you you will find the right solution.


在这里,试一试: http://jsfiddle.net/3KNnL/1/



I我不知道你想在哪里或如何创建/显示添加的框,所以我添加了一个函数,当你从Select元素中选择Paper选项时它会激活。希望它能让您了解去哪里。你必须在可见的地方添加一个隐藏的输入元素,或者动态创建一个元素并将其添加到DOM

使用类似的东西:

添加

Here you go, give this a try: http://jsfiddle.net/3KNnL/1/

I've got no idea where or how you'd like to create/display the added box, so I've added a function that will fire when you select the Paper option from that Select element. Hope it gives you an idea of where to go. You'll have to add a hidden input element somewhere that you make visible, or create an element dynamically and add it to the DOM
Using something like:
Adding
var newElem = document.createElement('input');
newElem.id = 'paperInputBox';
someElement.appendChild(newElem);



其中someElem是对已经获得的元素的引用。也许是带有id的td elem,用document.getElementById轻松找到它。




删除


Where someElem is a reference to an element that you've already obtained. Perhaps a td elem with an id, to make finding it easy with document.getElementById


Removing

var oldElem = document.getElementById('paperInputBox');
oldElem.parentNode.removeChild(oldElem);





我做了以下更改:

1.将代码从[No-wrap(body)]移动到[No-wrap(head)]

2.向'load'添加一个事件监听器'窗口事件

3.附加一个事件监听器给你指定的select元素。

4.在事件监听器中检查select elem的当前值。如果它是纸,我会显示一个警告框。您需要(1)使新框可见或(2)创建一个新框并将其添加到正确位置的文档中。 (不要忘记处理不再需要这个额外框的情况。即如果用户错误地选择Paper然后选择Real。)

lll



I've made the following changes:
1. Moved the code from [No-wrap (body)] to [No-wrap (head)]
2. Added an event listener to the 'load' event of the window
3. Attached an event listener to the select element you nominated.
4. Checked in the event listener for the current value of the select elem. If it's "Paper" I show an alert box. You'll need to either (1) make visible a new box or (2) create a new box and add it to the document at the correct place. (Don't forget to handle situations where this extra box is no longer required. I.e if the user selects "Paper" by mistake and then subsequently selects "Real".)
lll


这篇关于帮助javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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