I'm new with jquery but I will try to explain my problem the best I can, this is my problem: I have one input, i will write one random question inside it for example- How old are you? I have 2 buttons the first one says: Put above and the second one is put below ... now I already have 2 questions and one checkbox with each question, if I write on the input and click the first button that question will be the first question "it will be above the other ones (it will include the checkbox)" and if I click the second button it will be below the other ones "it will include the checkbox"
The question is, how can I do that, I need to save all the row? or how
Here is my source code, it's all that I have at this moment:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="style.css">
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/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>
<table><tbody>
<tr>
<td>Te gusta el cine?</td>
<td><input type="checkbox" value="1"/></td>
<td id="eliminar">Eliminar</td>
</tr>
<tr>
<td>Te gusta los tacos?</td>
<td><input type="checkbox" value="2"/></td>
<td id="eliminar">Eliminar</td>
</tr>
</tbody></table>
<button id="guardar" type="button">Guardar</button>
</div>
<div class="mi_clase">
</div>
</body>
</html>
And here is the 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);
});
$("#eliminar").click(function(){
});
$("#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();
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…