gpt4 book ai didi

jQuery:如何将变量分配回文档中的隐藏元素?

转载 作者:搜寻专家 更新时间:2023-10-31 22:50:49 24 4
gpt4 key购买 nike

如何将一个变量(被点击的按钮 ID)分配给 jQuery Diaglog,然后返回文档中的隐藏元素 (myhiddenid) 供以后使用?

<table border="0" class="time_data">
<td><button type="button" id='001' class="del-fruit" > Apple </td>
<td><button type="button" id='002' class="del-fruit" > Banana </td>
<td><button type="button" id='003' class="del-fruit" > Cantalope </td>
</table>

<div id='myhiddenid' style="display:none;"></div>

<script type="text/javascript">
$("#dialog-form").dialog({
autoOpen: false,
height: 150,
width: 350,
modal: true,
resizable: false,
buttons: {
'Yes': function() {
var bValid = true;
allFields.removeClass('ui-state-error');

bValid = bValid

if (bValid) {
//the assining of myhiddenid should be here!!
//and should contain the ID of the button that i clicked.
$(this).dialog('close');
}
},
No: function() {
$(this).dialog('close');
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});


$('.del-fruit')
.button()
.click(function() {
$('#dialog-form')
.dialog( "option", "title", this.id )
.dialog('open');
});
</script>

最佳答案

您可以使用隐藏字段并为其分配值,而不是 div:例如

HTML

<input type="hidden" id="hdnId" />

jQuery

$("#hdnId").val(id);

关于jQuery:如何将变量分配回文档中的隐藏元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5623666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com