我已经尝试了很多方法来获取jquery UI中被删除元素的id。请帮助获取id的值。
$( function() {
$(".draggable").draggable({
revert: "invalid",
helper: "clone"
});
$( "#droppable2" ).droppable({
drop: function( event, ui ) {
var draggable = ui.draggable;
var dragged = draggable.clone();
var currentID = ui.draggable.attr("id");/*draggable.find('id'); - returns an object. but, could not get the id. */
alert(dragged.html());
alert(currentID);
dragged.resizable();
dragged.appendTo("#droppable2");
//alert("open properties");
}
});
} );
被删除元素的html返回并包含id。
--- --- HTML
<div class="ui-widget-content draggable">
<select id='singleSelect'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</div>
<div id='droppable2' class="ui-widget-header" height='100%'><p/></div>
答案 0 :(得分:2)
您需要先找到private void UpdSalaryMonthTime_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
DataGridViewCheckBoxCell chk = item.Cells[0] as DataGridViewCheckBoxCell;
if (Convert.ToBoolean(chk.Value) == true)
{
connection.Open();
SqlCommand cmd = new SqlCommand(@"USE @Name
Update VariablesHistory
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update ContractFormulaSalaryHistory
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update FormulaSalaryHistory
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update ValueSalary
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update SalaryMonth
set [Month] = CAST(FLOOR(CAST([Month] AS FLOAT)) AS DATETIME)
Update LengthOfService
set [Month] = CAST(FLOOR(CAST([Month] AS FLOAT)) AS DATETIME)
Update Dekl1Value
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update Dekl1FormulaHistory
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update Dekl6Value
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
Update Dekl6FormulaHistory
set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)
--Update TaxRecalculationFormulaHistory
--set [Date] = CAST(FLOOR(CAST([Date] AS FLOAT)) AS DATETIME)", connection);
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Updated!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
,然后找到select
,因为id
会返回 nodeList ,正如我所说的那样我的评论,你使用了ui.draggable
标签错误,纠正了一下:
<p>
&#13;
$(function() {
$(".draggable").draggable({
revert: "invalid",
helper: "clone"
});
$("#droppable2").droppable({
drop: function(event, ui) {
var draggable = ui.draggable;
var dragged = draggable.clone();
var currentID = ui.draggable.find('select').attr('id');
console.log(currentID);
dragged.resizable();
dragged.appendTo("#droppable2");
//alert("open properties");
}
});
});
&#13;
答案 1 :(得分:1)
我想分享一下,您可以简单地使用以下代码来获取放置元素的ID /类名:
ui.draggable.attr("yourid/yourclass");
将此代码添加到您的droppable函数中。