0

我做了一个函数来输入一些字段并返回要显示的html:

function get_goodinput(GoodsSn, InCount, SellCount, Barcode, SinglePrice, BatchNo) {
    var $c = $('#t_addgoods_table').clone();
    $c.children("form").attr("id", "addgoods_form"); //id="t_addgoods_table"

    var $f = $c.children("form");

    $f.find("input[name='BatchNo']").val(BatchNo);
    $f.find("input[name='SinglePrice']").val(SinglePrice);
    $f.find("input[name='Barcode']").val(Barcode);
    $f.find("input[name='SellCount']").val("sssssssssssssssssssssss");
    alert($f.find("input[name='SellCount']").val());
    //this step can get the val..

    $f.find("input[name='InCount']").val(InCount);
    $f.find("select[name='GoodsSn']").val(GoodsSn);

    return $c.html();
}

并显示在metroUI 对话框中

$('#addgoods').click(function (e) {
    $.Dialog({
        'title' : '添加商品',
        'content' : get_goodinput("aaa", "aaa", "", "12", "12312", "aaaaa"),
        'draggable' : true,
        'buttonsAlign' : 'right',
        'closeButton' : true,
        'position' : {
            'zone' : 'center',
            'offsetY' : 100
        },
        'buttons' : {
            '确定' : {
                'action' : function () {

但我总是得到空输入......为什么?

在此处输入图像描述

HTML 代码:

在此处输入图像描述

4

1 回答 1

1

form 不能是 table 的子元素,只有 like 元素tr,tbody,thead,tfoot可以是子元素。

如果表格在表格内,则它必须在 a 中,TD以便您可以使用find()而不是children()

您也可能有无效的 html 进入对话框,因为您将表格的内部 html 而不是整个表格放入非表格元素中。html()方法采用元素的 innerHtml。

您可以将表格包装在 DIV 中并完全插入表格:

return $('<div>').append( $c ).html();
于 2013-02-19T04:14:37.927 回答