如何使用javascript选择器获取表td中的输入字段的值?

时间:2016-11-15 03:20:45

标签: javascript jquery html css

我有这行代码,它获取表格的td部分内的值。

<td>{{ $val->fname }}</td> 

上面的代码成功地获取了表格的td部分内的数据。 E.g

<td><input type='checkbox'style='width:30px; height:20px;' class='radio_check_all prod-id-checkbox' id='prod-id-checkbox' value="{{ $val->id }}"></td>

但是,如果td中有输入字段

If f.isFile() is true, then
 If f.getPath() ends with the extension, then
    Add f.getPath() to the foundFiles array list
 Return // this is the end of recursion
Else // This must be a directory
 For each subFile in f.listFiles() // This gets all the files in the directory
    Call findMatchingFiles(subFile) // This is the recursive call

它使用上面显示的代码返回输入字段的标记代码。它没有得到正确的价值。我该怎么办?请帮忙。感谢。

2 个答案:

答案 0 :(得分:1)

以下代码段应该可以使用

检查这个

&#13;
&#13;
#include <stdio.h>
#include <stdlib.h>
#define MaxSize 100
#define MaxData NULL

// Huffman tree的建树过程用最小堆时因为每次都可以挑出最小的两个元素组成

typedef struct TreeNode {
    int weight;
    struct TreeNode *left;
    struct TreeNode *right;
}HuffmanTree;

typedef struct HeapStruct {
    HuffmanTree *Elements[MaxSize+1];      // an array
    int Size;      // the number of item in array
    int Capacity;      /* the capacity of heap */
}MinHeap;



MinHeap *Create()
{   // create a empty heap
    MinHeap *H;
    H = (MinHeap *)malloc(sizeof(MinHeap));
    H->Elements[0] = NULL;
    H->Size = 0;
    H->Capacity = MaxSize;
    return H;
}

int isFull(MinHeap *H) 
{   // judge the heap full or not 
    return (H->Size == MaxSize);
}

int isEmpty(MinHeap *H)
{   // judge the heap empty or not
    return (H->Size == 0);
} 

void Add(MinHeap *H, int item)
{   // add item to the array
    if( isFull(H) )
    {
        printf("the heap is full.\n");
        return;
    }
    HuffmanTree *T;
    T = (HuffmanTree *)malloc(sizeof(HuffmanTree));
    T->weight = item;
    H->Elements[++(H->Size)] = T;
    return;
}

void Insert(MinHeap *H, HuffmanTree *item)
{   // insert item 
    int i;
    if( isFull(H) )
    {
        printf("the heap is full.\n");
        return;
    }
    i = ++(H->Size);
    for(; (H->Elements[i/2]->weight)>(item->weight);i/=2)
        H->Elements[i] = H->Elements[i/2];
    H->Elements[i] = item;
}

HuffmanTree *DeleteMin(MinHeap *H)
{   // delete item of the heap
    int Parent, Child;
    HuffmanTree *MinValueNode, *tempNode;
    if( isEmpty(H) )
    {
        printf("the heap is empty.\n");
        return NULL;
    }
    MinValueNode = H->Elements[1];
    tempNode = H->Elements[H->Size--];
    for(Parent=1; Parent*2<=H->Size; Parent=Child)
    {
        Child = Parent * 2;
        if( (Child != H->Size) && (H->Elements[Child]->weight > H->Elements[Child+1]->weight) )
            Child++;
        if( tempNode->weight <= H->Elements[Child]->weight )
            break;
        else 
            H->Elements[Parent] = H->Elements[Child];
    } 
    H->Elements[Parent] = tempNode;
    return MinValueNode; 
}

void PercDown(MinHeap *H, int i)
{   // adjustment of the heap 
    int Parent, Child;
    HuffmanTree *temp;
    temp = H->Elements[i];
    for(Parent=i; Parent*2<=H->Size; Parent=Child)
    {
        Child = Parent * 2;
        if( (Child != H->Size) && (H->Elements[Child]->weight > H->Elements[Child+1]->weight) )
            Child++;      // Child point to the min 
        if( temp->weight <= H->Elements[Child]->weight )    
            break;
        else        
            H->Elements[Parent] = H->Elements[Child];      
    }
    H->Elements[Parent] = temp;
}

void BuildMinHeap(MinHeap *H)
{ 
    int i;
    for(i=H->Size/2; i>0; i--)
        PercDown(H, i);
    return;
}

HuffmanTree *Huffman(MinHeap *H)
{   /* Assuming that H->Size weight hava existed in H->Elements[]->weight */
    int i;
    HuffmanTree *T;

    BuildMinHeap( H );     // adjustment 
    for(i=1; i<H->Size; i++)      // merge H->Size-1  
    {
        T = (HuffmanTree *)malloc(sizeof(HuffmanTree));      
        T->left = DeleteMin( H );      
        T->right = DeleteMin( H );     
        T->weight = T->left->weight + T->right->weight;     
        Insert(H, T); 
    }
    T = DeleteMin( H );
    return T;
}

void print_heap(MinHeap *H)
{
    if( isEmpty(H) )
    {
        printf("the heap is empty.\n");
        return;
    }
    for(int i=1; i<=H->Size; i++)
        printf("%d   ", H->Elements[i]->weight);
    printf("\n");
} 

void print_tree(HuffmanTree *T)
{
    if( T )
    {
        print_tree(T->left);
        printf("%d ", T->weight);
        print_tree(T->right);
    }
    return;
}

int main()
{
    MinHeap *heap;
    HuffmanTree *HT, *T;
    heap = Create();
    int x;
    printf("please input data:\n");
    scanf("%d", &x);
    while( x )
    {
        Add(heap, x);
        scanf("%d", &x);
    }   
    printf("original items:\n");
    print_heap( heap );
    printf("the item number of heap%d\n", heap->Size);
    BuildMinHeap(heap);
    print_heap( heap );
    HT = DeleteMin( heap );
    printf("删除的结点的值为%d\n", HT->weight);
    print_heap( heap );
    HT = Huffman( heap );
    print_tree( HT );
    return 0; 
}
&#13;
$(function(){
  var table=$("table");
  alert(table.find('tr td:eq(0) input').val());
});
&#13;
&#13;
&#13;

希望这有帮助

答案 1 :(得分:1)

所以你要说的是,如果表格单元格中的元素是输入,则返回该值。否则,如果它只是文本,则返回文本。

var $el = $('tr td:eq(0)'),
testEl = $el.has('input').length;

document.getElementById("supplierID").value = testEl ? $('input', $el).val() : $el.text();