0

I have a bunch of textboxes that are created dynamically one per click. They all have the same name "discount[]", same id "discount" and have the same class "tinput".

Is there anyway that I can use to change the text in all of these textboxes with javascript or jquery?

I have another bunch of the dynamically created text boxes. The id and name are unique but the class remains the same. If it gets the job done, I can change the class name.

Anyhelp is greatly appreciated.

Regards,

4

3 回答 3

1

您绝对不应该在每个文档中多次使用 id。如果您需要它,<label>您可能需要考虑将输入放入<label>.

不过,您正在以class正确的方式使用该属性。你可以做:

$('.tinput').val('New value for all .tinputs!');

如果您不能将输入放在标签内,则可以使用它。我不久前为某人制作了这个演示。这可能会有所帮助。它会增加一个像“id-1”这样的id。

http://jsbin.com/APegOMo/3/edit?html,js,输出

于 2013-09-22T17:17:27.777 回答
0

相同的ID“折扣”

请不要那样做!“id”是标识一个dom元素。这在我的灵魂中很痛。如果每个 id 都是唯一的,您可以通过 $("#myid").val("my new val") 访问它们。只是一个例子。

问候, - 托博

于 2013-09-22T17:12:04.407 回答
0

这是一个简单的示例,它采用具有特定类名的所有元素并更改 .html,但不是 100% 确定我理解您所追求的。如果您需要对每个 div 文本做一些特定的事情,您可以通过 id(也可能是类)遍历它们并更改每个 div 单独的 .html。

如果您可以分享您的代码的精简示例或详细说明,我很乐意提供帮助。祝你好运。

$(".changeDivs").html("adfasdf");

jsfiddle 示例 >>

于 2013-09-22T17:27:35.467 回答