2010-05-12 89 views
0

我有7个文本框。如果前1个文本框(Volume All Years Years)文本发生更改,则需要在接下来的6个输入框中更新文本(最新的2009年最近2014年的卷数量)。我需要JavaScript或Jquery。我将为前1个文本框编写Js textchanged()或focuschange()。所以,我应该写在focuschage()或框TextChanged方法()当文本更改输入框自动更新下6个文本框

<tr id="row12_136" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Volume All Years</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_136" type="text" maxlength="255" id="12_136" tabindex="61" title="Volume All Years" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
        </td> 
       </tr><tr id="row12_60" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2009 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_60" type="text" maxlength="255" id="12_60" tabindex="62" title="Latest 2009 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_60" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl47" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
       </tr><tr id="row12_61" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2010 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_61" type="text" maxlength="255" id="12_61" tabindex="63" title="Latest 2010 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_61" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl48" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
       </tr><tr id="row12_62" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2011 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_62" type="text" maxlength="255" id="12_62" tabindex="64" title="Latest 2011 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_62" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl49" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
       </tr><tr id="row12_63" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2012 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_63" type="text" maxlength="255" id="12_63" tabindex="65" title="Latest 2012 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_63" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl50" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
       </tr><tr id="row12_64" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2013 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_64" type="text" maxlength="255" id="12_64" tabindex="66" title="Latest 2013 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_64" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl51" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
       </tr><tr id="row12_65" class="RegText"> 
        <td style="width:420px;Padding-right:20px;">Latest 2014 Volume*</td> 
        <td style="width:420px;Padding-left:0px;"> 
         <input name="12_65" type="text" maxlength="255" id="12_65" tabindex="67" title="Latest 2014 Volume" class="textbox" OnKeyPress="javascript:FocusChange();" style="width:300px;" /> 
         <span controltovalidate="12_65" errormessage="* Required!" display="Dynamic" validationGroup="ValidateInsert" id="_ctl52" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="" style="color:Red;display:none;">* Required!</span> 
        </td> 
+0

你将如何改变它们,这意味着应该在其中放入什么数据?如果数据在后端检索或计算,则涉及更多工作。 – 2010-05-12 02:00:20

+0

我只是想从textbox1复制文本到textbox2 ... textbox7。只需复制数据。 – James123 2010-05-12 02:08:05

回答

0

随着该HTML,并在#foo是选择对相应的表在零:

$('tr.RegText input:eq(0)').change(function() { 
    $('tr.RegText input:gt(0):lt(7)').val($(this).val()); 
}); 

这是假设的变化对第一个输入字段的模糊是可以接受的。改变密码或任何品尝。

+0

对不起... Wombleton ..我不明白你的代码。我的表没有ID。它没有为我工作。和一个 – James123 2010-05-12 03:08:27

+0

“#foo”是一个占位符,用于任何css选择器,让您可以找到这些行所在的表。除非您的表具有id“foo”,否则它将无法工作。如果它有一个类,或者在DOM中找到它,你可以使用它。代替使用tr.RegText更新选择器。 – wombleton 2010-05-12 03:35:33

0

使用jQuery:

$("#12_136").keyup(function(){ 
    var $myVal = $("#12_136").val(); 
    for(var i = 0; i < 6; i ++) { 
    $("#12_6"+i).val($myVal); 
    } 
}); 
+0

谢谢摇滚,这工作正常。有什么方法改变#12_136和“#12_6”+我并使用别的东西。喜欢使用标题“最新...” – James123 2010-05-12 03:03:45

0

拖放在您的HTML内嵌的按键事件。您可以在运行时轻松附加事件处理程序。

有了jQuery,你可以这样做。我正在使用“onchange”。我认为你不需要在按键水平上做到这一点。

$(document).ready(function() { init() }) 


function init() {  
    $('#12_136').change(function() { 
      var myVal = $(this).attr('value') 
      $(this).parents('table').find('input').attr('value',"#" + myVal + "#") 
    }) 
} 
+0

感谢Diodeus,我在该表中还有其他一些输入框。我只是想为下面的6个输入框添加值。我认为在你的代码中它会为该表中的所有输入文本框添加值。 – James123 2010-05-12 03:11:56

+0

它会的。您只能通过为其添加类名来选择这六个选项。然后用.find('input.yourClass')替换:.find('input') – 2010-05-12 04:31:53