javascript - Contenteditable 不适用于 javascript

标签 javascript jquery html

我想做的是将行设置为可在单击按钮时编辑。

$(":button").click(function(){

 var tdvar=$(this).parent('tr').find('td');
  $.each(tdvar,function(){
    $(this).prop('contenteditable',true); 
  });
});
  <s:iterator  value="arr">  
      <tr>
        <td contenteditable="false"><s:property value="%{productname}"/></td>
        <td contenteditable="false"><s:property value="%{category}"/></td>
        <td contenteditable="false"><s:property value="%{price}"/></td>
        <td contenteditable="false"><s:property value="%{stock}"/></td>
        <td>
          <span class="table-remove glyphicon glyphicon-remove"></span>
        </td>
        <td>
          <span class="table-up glyphicon glyphicon-arrow-up"></span>
          <span class="table-down glyphicon glyphicon-arrow-down"></span>
        </td>
        <td><button class="edt">edit</button>
        </td>
      </tr>
      </s:iterator>  

最佳答案

查找parent().parent('tr')

$("button").click(function() {
  var tdvar = $(this).parent().parent('tr').find('td'); //change on this line 
  $.each(tdvar, function() {
    $(this).prop('contenteditable', true);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>

  <tr>
    <td contenteditable="false"><s:property value="%{productname}" /></td>
    <td contenteditable="false"><s:property value="%{category}" />1</td>
    <td contenteditable="false"><s:property value="%{price}" />2</td>
    <td contenteditable="false"><s:property value="%{stock}" />3</td>
    <td>
      <span class="table-remove glyphicon glyphicon-remove"></span>
    </td>
    <td>
      <span class="table-up glyphicon glyphicon-arrow-up"></span>
      <span class="table-down glyphicon glyphicon-arrow-down"></span>
    </td>
    <td>
      <button class="edt">edit</button>
    </td>
  </tr>
</table>

关于javascript - Contenteditable 不适用于 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48200730/

相关文章:

javascript - 下划线方法 _.template() 不编译我的模板

asp.net-mvc - ASP.NET MVC : Making an Xdocument available to jquery?

javascript - 如何在 Protractor 测试中获取 Web 服务响应

jquery - 无效链接直到滚动

javascript - 导航菜单翻译网页时水平滚动并溢出隐藏

javascript - jQuery - 显示div的出现次数

javascript如何在滚动路线上 move 元素

javascript - 歌剧错误 : Uncaught exception: TypeError: Cannot convert 'xxxxxx' to object

javascript - 如何选择具有相同类名的特定<span>?

html - div 下方出现空白