我有以下代码:
<div id="main" style="width: 500px; height: 500px; background: #ddd; float: left;"></div>
<div id="list" style="width: 200px; height: 500px; border: 1px solid #ddd; float: left; margin-left: 15px;">
<div class="section">
Ja/Nej
<div class="showforms" style="display: none;">
<strong>Fritext</strong>
<input type="text" name="question">
<p><input type="radio" name="test" value=1> Ja<br>
<input type="radio" name="test" value=0> Nej<br></p>
<input type="submit" name="save" value="Spara" class="save">
</div>
</div>
<div class="section">
Option list
<div class="showforms" style="display: none">
<select>
<option>Fisk</option>
<option>Fisk2</option>
</select>
</div>
</div>
</div>
$(document).ready(function() {
var jsonObj = [];
var i = 0;
$('.section').draggable({
revert: "invalid",
stack: ".yesorno",
helper: "clone"
});
$('#main').droppable({
accept: ".section",
drop: function(event, ui) {
//Lagra ui-objektet i en lista
//Loopa ut objekten och sätt ett index på varje classnamn och visa input fältet
jsonObj[i] = {"Objekt": ui.draggable, "Id": i};
var draggable = jsonObj[i]["Objekt"];
var droppable = $(this);
draggable.show('.showforms');
draggable.clone().appendTo(droppable);
$("#main").find("div").attr('id', i).show();
var testa = $('#main').find("div")[i];
var submit = $(testa).find(":submit").attr('test', i);
console.log($(testa).find(":submit"));
//Object[div#yesorno.ui-draggable.ui-draggable-handle]
i++;
}
});
});
$('.save').click(function() {
console.log("hej"); //This don't work
});
我在这里做的事情是我采用了一个包含一些隐藏的输入字段的section-div。我将它拖入main-div并将其放在此处。删除它后,将显示输入字段。
我遇到的问题是我在Main-div中拖放它后点击提交按钮时没有打印出来。我做错了什么?
答案 0 :(得分:0)
尝试: 取代
var price = "12,000.50";
price = price.replace(/[,]+/g, '');
return price.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.");
使用
<input type="submit" name="save" value="Spara" class="save">
替换
<input type="submit" name="save" value="Spara" class="save" onClick="saveFunction()">
使用
$('.save').click(function() {
console.log("hej"); //This don't work
}
答案 1 :(得分:0)
我通过这样做解决了它:
$(document).on('click', ".save", function() {
console.log($(this).attr('test'));
});