gpt4 book ai didi

javascript - 获取 jquery 中 div 的特定输入(子)元素的 id 或类名

转载 作者:行者123 更新时间:2023-11-29 17:49:17 26 4
gpt4 key购买 nike

我使用波纹管代码动态创建了表格。在此表中,第 4 个 td 具有动态数据和 div 我想要的是当用户选择文本框想要删除子 div 然后附加文本框或如果他选择 fileupload 则仅在该 td 标记中附加上传字段

//some lines of table opening and header code comes here
$.each(data,function(key,value){
MoreTag += '<tr><td style="width: 10px">'+value.Id+'</td>';
MoreTag += '<td>'+value.installment_number+'</td>';
MoreTag += '<td>'+value.instal_title+'</td>';

//4th td element
MoreTag += '<td id="tabledata">'+
'<div id="fields'+value.installment_number+'">'+
'<label style="font-weight:normal"><input name="resp'+value.installment_number+'" type="radio" id="textbox" class="textbox">&nbsp;Text Box</label>'+
'&nbsp;<label style="font-weight:normal"><input name="resp'+value.installment_number+'" type="radio" id="fileupload" class="fileupload">&nbsp;File Upload</label>'+
'</div></td>';
MoreTag += '<td>'+value.instal_amount+'</td></tr>';
});
MoreTag += '</tbody>';
MoreTag += '</table>';
MoreTag += '</div>';
$('#listofstudloanschedules').append(MoreTag);

我正在尝试这个脚本

var childinput = '';
$(document).on('change',"#tabledata",function(){
var name = $(this).children("div").prop("id");
$("#" + name + " input").click(function(){
childinput = $(this).attr("id");
alert(childinput);
});
});

通过这个我得到了特定的字段 ID 或类名。

问题但是对于第 4 行 td 的每一行,第一次点击都没有提醒..

最佳答案

让我给你一个简单的代码片段,但你必须根据你的要求修改输入类型单选按钮的值

$(document).ready(function() {
$('input[type=radio]').change(function() {
if (this.value == 'textbox') {
alert("textbox");
}
else if (this.value == 'uploadfile') {
alert("uploadfile");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<td id="tabledata">
<div id="text_fields">
<label style="font-weight:normal"><input name="resp'+value.installment_number+'" type="radio" id="textbox" class="textbox" value="textbox">Text Box</label>
<label style="font-weight:normal"><input name="resp'+value.installment_number+'" type="radio" id="fileupload" class="fileupload" value="uploadfile">Upload File</label>
</div>
</td>

关于javascript - 获取 jquery 中 div 的特定输入(子)元素的 id 或类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45635156/

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