Javascript 动态手风琴发帖与应答
我有这把小提琴 我可以创建一个带有按钮的动态手风琴 在每个手风琴内,我需要制作另一个文本区域和按钮,以便在同一折叠中添加另一个文本Javascript 动态手风琴发帖与应答,javascript,jquery,html,twitter-bootstrap,model-view-controller,Javascript,Jquery,Html,Twitter Bootstrap,Model View Controller,我有这把小提琴 我可以创建一个带有按钮的动态手风琴 在每个手风琴内,我需要制作另一个文本区域和按钮,以便在同一折叠中添加另一个文本 但我面临的问题是,即使父id也是动态的,我如何每次都获取按钮的父id呢。这里需要采取的几个步骤: 首先,在本例中,您需要以稍微不同的方式绑定单击(),因为您希望以友好方式单击 添加元素 其次,我们使用closest()方法和attr('id') 获取textarea值时,可以使用 $(this.parent().prev().find('textarea').va
但我面临的问题是,即使父id也是动态的,我如何每次都获取按钮的父id呢。这里需要采取的几个步骤:
- 首先,在本例中,您需要以稍微不同的方式绑定单击(),因为您希望以友好方式单击 添加元素
- 其次,我们使用
方法和closest()
attr('id')
- 获取
值时,可以使用textarea
$(this.parent().prev().find('textarea').val()
- 然后使用
方法将文本追加到所需单词的旁边,最后使用append()
在单词前面添加文本(这有点不清楚,所以我在PrepBootstrap的$(this).closest('.container').append(answer)
帐户注册之前添加了它。我希望这就是你的意思)
var x=1;
$(文档)。在('单击',“#添加ID”,函数()上{
var idOfParent=$(this).closest('.panel collapse').attr('id');
//console.log(idOfParent);
var answer=$(this.parent().prev().find('textarea').val();
$(this).最近('.container')。追加(应答);
});
$(文档)。在('click','#AddQuestId',函数()上{
x=x+1;
$(“#手风琴”)。附加(“”)+
'' +
' ' +
' ' +
'' +
'' +
'' +
' ' +
' ' +
'' +
回答:+
' ' +
' ' +
' ' +
'' +
'' +
'在预引导中注册帐户'+
'' +
'' +
'' +
'' +
'');
});代码>
评论:
让我们看看。这里需要采取的几个步骤:
- 首先,在本例中,您需要以稍微不同的方式绑定单击(),因为您希望以友好方式单击
添加元素
- 其次,我们使用
closest()
方法和attr('id')
- 获取
textarea
值时,可以使用
$(this.parent().prev().find('textarea').val()
- 然后使用
append()
方法将文本追加到所需单词的旁边,最后使用$(this).closest('.container').append(answer)
在单词前面添加文本(这有点不清楚,所以我在PrepBootstrap的帐户注册之前添加了它。我希望这就是你的意思)
var x=1;
$(文档)。在('单击',“#添加ID”,函数()上{
var idOfParent=$(this).closest('.panel collapse').attr('id');
//console.log(idOfParent);
var answer=$(this.parent().prev().find('textarea').val();
$(this).最近('.container')。追加(应答);
});
$(文档)。在('click','#AddQuestId',函数()上{
x=x+1;
$(“#手风琴”)。附加(“”)+
'' +
' ' +
' ' +
'' +
'' +
'' +
' ' +
' ' +
'' +
回答:+
' ' +
' ' +
' ' +
'' +
'' +
'在预引导中注册帐户'+
'' +
'' +
'' +
'' +
'');
});代码>
评论:
您的问题不清楚。。你能一步一步地详细说明你面临的问题吗?希望能有所帮助!你的问题不清楚。。你能一步一步地详细说明你面临的问题吗?希望能有所帮助!
$("#AddansId").click(function(){
//get the parent of the div with id(Collapse+x)
// to abend the data content of the textarea beside the word
//Account Registeration at PrepBootstrap
});