简体   繁体   English

如何动态地插入一个始终具有与VB.net页面上其他位置的值相同的文本框的文本框?

[英]How would I dynamically insert a textbox that has the same values at all times as a different textbox elsewhere on the page in VB.net?

The problem: Postback time must not happen. 问题:回发时间一定不能发生。 So the generation of the HTML/ASP.net literals are done on Page_Load. 因此,HTML / ASP.net文字的生成是在Page_Load上完成的。 Since the user hasn't entered a value for the textboxes that I do calculations on yet, I can't copy those boxes (for a confirmation page) at runtime. 由于用户尚未输入要在其上进行计算的文本框的值,因此我无法在运行时复制这些框(用于确认页面)。

If I was able to make the VB backend do something conceptually like: 如果我能够使VB后端在概念上执行以下操作:

$("[id$='TEXTBOX1']").change( function() {
$("[id$='TEXTBOX1_COPY']").val( $("[id$='TEXTBOX1']").val()  );
});

for each item, but dynamically from the backend, that would be perfect. 对于每个项目,但从后端动态地进行,那将是完美的。

Is it possible? 可能吗? If I can utilize javascript to do it, that'd be alright too but I'm wondering if there is an easier way than using literals and placeholders to insert textboxes and dynmaically create the code above in javascript on the backend for each element (because the number of elements I'm going to be adding will be unknown - can't hardcode it) 如果我可以利用javascript做到这一点,那也可以,但是我想知道是否有比使用文字和占位符插入文本框并在后端的javascript中为每个元素动态创建上面的代码更简单的方法(因为我要添加的元素数量未知-无法对其进行硬编码)

I think this could be what you are looking for: 我认为这可能是您要寻找的:

    <input type="text" id="first_source" />
    <input type="text" id="second_source" />
    <input type="text" id="3_source" />
    <hr />
    <input type="text" id="first_copy" />
    <input type="text" id="second_copy" />
    <input type="text" id="3_copy" />

and: 和:

    $('input[id*="source"]').keyup(function(e)
    {
        var id = $(this).attr('id').split('_')[0];
        $('input[id*="'+ id +'_copy"]').val( $(this).val())
    });​

I've changed the event from .change to .keyup for a fancier effect :D 我已将事件从.change更改为.keyup以获得更奇特的效果:D

http://jsfiddle.net/CqccF/2/ http://jsfiddle.net/CqccF/2/

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

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