2016-07-15 35 views
0

我有一个表,当我点击一个按钮时,我想将contenteditable设置为true,然后将焦点放在td元素上客户端看到单元格中的光标闪烁。无法集中在我的表中点击事件的​​元素

我似乎无法获取焦点对LicenseName电池工作。我知道'tableData'变量包含正确的元素,我在浏览器调试器中检查过它。

这是我试过的。

editLicensesDetails = function (e) { 
 
     var tableRow = $(e.target).parent().parent(); 
 
     $(tableRow).css('background-color', '#dff0d8'); 
 
     $(tableRow).children('[contenteditable]').attr("contenteditable", "true"); 
 
     var tableData = $(tableRow).children('[contenteditable]')[0]; 
 
     $(tableData).focus(); 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table id="tableLicenseDetails" style="width:100%;"> 
 
        <tr> 
 
         <th>Edit</th> 
 
         <th>Delete</th> 
 
         <th>Name</th> 
 
         <th>Description</th> 
 
         <th>Product</th> 
 
         <th>Unit Of Measure</th> 
 
         <th>Variable Rate</th> 
 
        </tr> 
 
        <tr> 
 
          <td style="display:none;">@license.LicenseId</td> 
 
          <td> 
 
           <i class="fa fa-pencil" aria-hidden="true"></i> 
 
          </td> 
 
          <td> 
 
           <i class="fa fa-trash" aria-hidden="true"></i> 
 
          </td> 
 
          <td contenteditable="false">@license.LicenseName</td> 
 
          <td contenteditable="false">@license.LicenseDescription</td> 
 
          <td>@license.TradePulseProductName</td> 
 
          <td>@license.LicenseUnitOfMeasureTypeName</td> 
 
          <td>@license.IsVariableRate</td> 
 
         </tr> 
 
       </table>

+0

? – bwyn

回答

0

您的代码是否正常工作。这意味着什么是错的,当你调用editLicensesDetails功能

var tableRow = $('tr'); 
 
    $(tableRow).css('background-color', '#dff0d8'); 
 
    $(tableRow).children('[contenteditable]').attr("contenteditable", "true"); 
 
    var tableData = $(tableRow).children('[contenteditable]')[0]; 
 
    $(tableData).focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td contenteditable="false">LicenseName</td> 
 
    <td contenteditable="false">LicenseDescription</td> 
 
    
 
    </tr> 
 
</table>

您使用的是什么浏览器
+0

我知道我在editLicenseDetails函数和变量'tableData'中获得了正确的数据,我有正确的元素(​​)。我还能看到什么? – user1186050

+0

@Tushar Gupta:您的代码段使用Google Chrome浏览器适用于我,但tds无法修改,也无法通过Internet Explorer获得关注。 – bwyn

相关问题