Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery中使用表_Javascript_Jquery - Fatal编程技术网

Javascript 如何在jquery中使用表

Javascript 如何在jquery中使用表,javascript,jquery,Javascript,Jquery,我是jquery新手,但我会尽力解释我的问题,这是我的问题: 我有一个输入,我会在里面写一个随机的问题,例如-你多大了?我有两个按钮,第一个说:放在上面,第二个放在下面。。。现在我已经有了两个问题,每个问题都有一个复选框,如果我在输入上写下并单击第一个按钮,该问题将是第一个问题“它将位于其他问题之上(它将包含复选框)”,如果我单击第二个按钮,它将位于其他问题之下“它将包含复选框” 问题是,我如何才能做到这一点,我需要保存所有的行?或者如何 这是我的源代码 <head> <

我是jquery新手,但我会尽力解释我的问题,这是我的问题: 我有一个输入,我会在里面写一个随机的问题,例如-你多大了?我有两个按钮,第一个说:放在上面,第二个放在下面。。。现在我已经有了两个问题,每个问题都有一个复选框,如果我在输入上写下并单击第一个按钮,该问题将是第一个问题“它将位于其他问题之上(它将包含复选框)”,如果我单击第二个按钮,它将位于其他问题之下“它将包含复选框”

问题是,我如何才能做到这一点,我需要保存所有的行?或者如何

这是我的源代码

<head>
    <title></title>
    <meta charset="utf-8"/>
    <script src="js/jquery-2.1.4.min.js"></script>
    <script src="jquery-1.12.0.js"></script>
    <script src="jquery.js"></script>
    <script src="file2.js"></script>    
</head>
<body>
    <div id="id" class="mi_clase">
        <input type="text" id="pregunta">
        <button id="arriba" type="button">Poner arriba</button>
        <button id="abajo" type="button">Poner abajo</button>
        <a href="#" class="delete">Eliminar Fila</a>
        <table class="table">
            <tbody>
                <tr>
                    <td>Te gusta el cine?</td>
                    <td><input type="checkbox" value="1"/></td>
                </tr>
                <tr>
                    <td>Te gusta los tacos?</td>
                    <td><input type="checkbox" value="2"/></td>
                </tr>
            </tbody>
        </table>
        <button id="guardar" type="button">Guardar</button>     
    </div>
    <div class="mi_clase">
    </div>
</body>

波内阿里巴
波内尔阿巴乔
你喜欢看电影吗?
你喜欢墨西哥玉米卷吗?
瓜达尔
这是我的js

$(document).ready(function() {
    $("#guardar").click(function() {
        var seleccionados = $.makeArray($(':checkbox').map(function(i, item) {
            if ($(item).is(':checked'))
                return parseInt($(item).val());
        }));

        console.log(seleccionados);
    });

    $('.delete').on('click', function() {
        $('.table input:checked').closest('tr').hide()
    });

    $("#arriba").click(function() {
        var p = $("#pregunta").val();
        console.log(p);
        var td1 = $("<td></td>").text(p);
        var td2 = $("<td><input type='checkbox' value='2' /></td>");
        var td3 = $("<td></td>");
        if (p != "") {

        }
    });

    $("#abajo").click(function() {

        if ($("#pregunta").val() != "") {
            $("tbody").append();
        }
    });

});
$(文档).ready(函数(){
$(“#guardar”)。单击(函数(){
var seleccionados=$.makeArray($(':checkbox').map(函数(i,项){
如果($(项).is(':checked'))
返回parseInt($(item).val());
}));
console.log(selectionados);
});
$('.delete')。在('click',function()上{
$('.table input:checked').closest('tr').hide()
});
$(“#arriba”)。单击(函数(){
var p=$(“#pregunta”).val();
控制台日志(p);
变量td1=$(“”)。文本(p);
变量td2=$(“”);
变量td3=$(“”);
如果(p!=“”){
}
});
$(“#abajo”)。单击(函数(){
如果($(“#pregunta”).val()!=”){
$(“tbody”).append();
}
});
});

要添加/前置新行,可以使用以下代码。请参阅代码中的注释。最后使用
append
将新行添加为最后一行,或使用
prepend
将新行添加为第一行。嗯

function createNewRow(){
    var p = $("#pregunta").val();

    // create the new elements first
    var $tr = $("<tr>");
    var $td1 = $("<td>");
    var $td2 = $("<td>");
    var $input = $("<input>", {"type": "checkbox", "value": "2"});

    // append text to cell 1
    $td1.append(p);

    // append input to cell 2
    $td2.append($input);

    // append cells 1 and 2 to new row              
    $tr.append($td1);
    $tr.append($td2);

    return $tr;
}

// get body and prepend row to body
$("#arriba").click(function() {
    var $tr = createNewRow();
    var $tableBody = $(".table tbody");
    $tableBody.prepend($tr);
});

// get body and append row to body
$("#abajo").click(function() {
    var $tr = createNewRow();
    var $tableBody = $(".table tbody");
    $tableBody.append($tr);
});

问题是什么?你好像忘了写问题。您编写了需求,而不是问题。
这是我的js
-您将一次解决一个问题,对吗?欢迎来到全堆栈溢出编程世界我编辑了它,我忘记了问题,我病了,不能清晰地思考,谢谢您的帮助,欢迎任何帮助,所以我需要复制所有这些,除了$tableBody.append($tr);“如果我想把它放在prepend上?例如”这就是我想要的,非常好的信息和如何做的解释,thxI很高兴它能帮助你,并祝你早日康复:)。
$(".table tbody").prepend(createNewRow());