简体   繁体   English

jQuery在窗体内选择div类并添加值

[英]jquery select div class inside a form and add value

I have a form in my modal and I can select like : 我的模态中有一个表单,可以选择如下形式:

$(".my-modal").click(function () {
        var app_modal = $(this).next('.modal').modal({backdrop: 'static'})
        var frm = app_modal.next('.myform')
        console.log(frm)
        frm.on('submit', function(event){
            event.preventDefault();
            frm.class('.result').html('<div>Hellooww</div>');
        });

and my form is: 我的形式是:

<form class="myform">
<div class="results"></div>
some form element
</form>

Here I want to put some html on class .results but I am unable to do this.. The form is in form loop in django template 在这里,我想在类.results上放置一些html ,但是我无法做到这一点。. form loop in django template处于form loop in django template

How can I do this ?? 我怎样才能做到这一点 ??

jQuery has no .class() function. jQuery没有.class()函数。 Instead you can use .find() if the result element is a descendent of the form: 如果结果元素是以下形式的后代,则可以使用.find()

frm.find('.result').html('<div>Hellooww</div>');

If the result element is a sibling of the form then you can go up to the parent and find it like so 如果result元素是表单的同级元素,则可以转到父级并找到它,如下所示

frm.parent().find('.result').html('<div>Hellooww</div>');

这可能起作用:

frm.children(".results").html('<div>Hellooww</div>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM