0

我在表格中有一组文本框,我想通过按 shift+down 箭头来选择多个文本框值。在选择文本框时,应将值复制并存储在数组中...请有人帮帮我...

<style>
  #feedback { font-size: 1.4em; }
  #selectable .ui-selecting { background: #FECA40; }
  #selectable .ui-selected { background: #F39814; color: white; }
  #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  </style>
<script>

$(function(e) {


    $( "#selectable" ).selectable({selected: function( event, ui ) {alert(this)}});
  });

</script>
<body>
<table width="78%" border=1 id="selectable" style="border-collapse:collapse">
<tr>
<td><input type="text" class="ui-widget-content"   /></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>

</tr>
<tr>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>

</tr>
<tr>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>

</tr>
<tr>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>
<td><input type="text"  class="ui-widget-content"/></td>

</tr>
</table>
</body>
</html>
4

3 回答 3

0

使用 jQuery。

您可以使用

 $("your id").keypress(function(e){
    //here you find e.KeyCode if it is equal to shift+down_arrow then take the values of text box here as $("#yout text box id").val(); and store it into an array.

    });
于 2013-10-09T07:58:12.547 回答
0

这是一段代码,可让您选中未选中的框并获取这些框的值(使用 Shift + 向上/向下箭头)...

完整的工作代码在这里=>小提琴

您可以稍微调整一下,使其适合您的需求。

$(function () {
    var keys = {},    // Keys strokes state
        storage = {}; // Tracking of checked checkboxes values
    $(document).keydown(function (e) {
        // UPDATE Keys strokes state to memorize simultaneous keydown ...
        // THEN update values storage
    }).keyup(function (e) {
        // UPDATE Keys strokes to remove released keys
    }).click(function(e){
        // UPDATE values storage in case a checkbox get clicked ...
    });
});
于 2013-10-09T11:05:20.967 回答
0

基于以下问题:

  1. 左键单击
  2. 降档

        $(function(e) {
          var store = {
            selectedText: ''
          };
          $("#selectable").bind('mousedown', function(e) {        
            if (e.shiftKey && e.which === 1) {
              store.selectedText += e.target.value;
              $('#selectedText').html(store.selectedText);
            }
          });
        });
    

JsFiddle

于 2013-10-09T08:11:28.257 回答