jQuery 附加多个元素不仅仅是(this)
好吧,这可能看起来很奇怪我要求做的事情(因为我知道这不是最好的方法)
这是我的 jquery 代码:
$('.save_ref').live('click',function(){
var project_ref_input=$('.project_ref_input').val();
$('.project_ref').append(project_ref_input);
});
我有一个表,我通过 .append() 动态添加行,然后我在每行的末尾有一个名为project_ref_input的输入和一个保存按钮。我需要做的是,当用户输入某些内容并按下“保存”时,输入文本将被附加到名为 .project_ref 的 ap 标记中。但是,我在新表中有多行,因此当我将值放入输入时,其附加的值都是相同的!?
这就是我制作表格的方式:
$('#items').append('<tr class="tableRow"><td><a class="removeItem" href="#"><img src="/admin/images/delete.png"></img></a><td class="om_part_no">' + omPartNo + '</td><td>' + supPartNo + '</td><td>' + cat + '</td><td class="description">' + desc + '</td><td>' + manuf + '</td><td>' + list + '</td><td>' + disc + '</td><td class="price_each_nett price">' + priceEach + '</td><input type="text" class="project_ref_input" name="project_ref_input" /><p class="project_ref"></p></tr>');
Ok this may seem weird what i'm requesting to do (because i know its not the best way to do it)
This is my jquery code:
$('.save_ref').live('click',function(){
var project_ref_input=$('.project_ref_input').val();
$('.project_ref').append(project_ref_input);
});
I have a table and i'm adding rows to it dynamically by .append() then i have an input at the end of each row called project_ref_input and a save button. What i need to do is when the user inputs something and presses save, for the input text to be appended to a p tag called .project_ref. However i have multiple rows in the new table so when i'm putting values into the inputs its appending them all the same!?
This is how i make the table:
$('#items').append('<tr class="tableRow"><td><a class="removeItem" href="#"><img src="/admin/images/delete.png"></img></a><td class="om_part_no">' + omPartNo + '</td><td>' + supPartNo + '</td><td>' + cat + '</td><td class="description">' + desc + '</td><td>' + manuf + '</td><td>' + list + '</td><td>' + disc + '</td><td class="price_each_nett price">' + priceEach + '</td><input type="text" class="project_ref_input" name="project_ref_input" /><p class="project_ref"></p></tr>');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用全局选择器来选择元素。
$('.project_ref_input') - 获取类为“project_ref_input”的所有元素
您需要更具体地了解要处理的输入。
如果您直接在“保存”按钮之前输入,这可能会起作用:
You are using global selectors, to select your elements.
$('.project_ref_input') - get all elements with class "project_ref_input"
You need to be more specific about which input you want to process.
If you input is directly before "Save" button this might work:
这最终成功了!
感谢银光的帮助
This worked in the end!
Thanks for help Silver Light