【问题标题】:Create textbox dynamically in td next to specified td in html table using jquery使用jquery在html表中指定td旁边的td中动态创建文本框
【发布时间】:2016-07-11 15:26:01
【问题描述】:

大家好, 我需要动态创建文本框(取决于条件),当用户点击员工时,它应该被添加到员工旁边,如果用户点击另一个元素,它应该被添加到另一个元素旁边

我尝试过关注,但我无法获得准确的 td 和函数,我可以通过这些函数将文本框附加到它。

$("#emlpyeetd").after('<s:textfield id="employeeVal" name="employeeView.policyOrQuoteNumber" maxlength="15" style="width: 200px;" class="hideForAnotherField" theme="simple"></s:textfield>');


<td width="25%">
  employee
</td>
<td id="policytd" class= "anotherfield" width="25%"></td>

【问题讨论】:

  • 你能给jsfiddle你试过的代码吗?
  • 发布您的html,是的,无论您目前尝试实现什么......
  • 对不起,我忘了添加我的代码。请找到我的代码

标签: javascript jquery html


【解决方案1】:

试试这样,当你点击第二个选项时,它会删除第一个文本框。

jQuery 代码

<script>
$(document).ready(function(){

    $(".radio_action").click(function(){

        if($(this).val() == "E" ){ 

            $("#other_text").html(""); 
            $("#emp_text").html("<input type='text' >"); 
        }
        else if($(this).val() == "A" ) { 
            $("#emp_text").html("");        
            $("#other_text").html("<input type='text' >"); 
        }
    })      
});
</script>

HTML 代码

<table>
<tr>
    <td><input type="radio" name="radio_type" value="E" class="radio_action" /> Employee</td>
    <td id="emp_text"></td>
</tr>
<tr>
    <td><input type="radio" name="radio_type" value="A" class="radio_action" /> Another Element</td>
    <td id="other_text"></td>
</tr>
</table>

【讨论】:

    【解决方案2】:
    Html
    
    <div>
      <div class="container">
        <div><input type="radio"/ name="somename" value="1">Val1</div>
        <div class="editor-wrapper"></div>
      </div>
      <div class="container">
        <div><input type="radio"/ name="somename" value="1">Val2</div>
        <div  class="editor-wrapper"></div>
      </div>
    </div>
    

    JS

    $(document).ready(function() {
       $('input[name="somename"]').click(function() {
        $(this.closest('.container')).find('.editor-wrapper').html($('<input>'))
       });
    });
    

    jsfiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 2012-10-07
      • 2014-04-29
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多