动态添加Texbox并随机删除任何texbox,并将所有数据保存在数据库中. [英] Dynamically Add Texboxes and Delete any texbox randomly, and save all data in database.

查看:76
本文介绍了动态添加Texbox并随机删除任何texbox,并将所有数据保存在数据库中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要动态添加文本框,并为每个文本框添加删除按钮,除此之外,还应删除该文本框,然后在保存按钮上使用MVC3 Razor视图向控制器提供所有数据.所以我没有任何使用.cshtml文件的razor视图使用aspx.cs文件.

我尝试使用Jquery,但无法随机删除文本框,
我可以删除最后添加的文本框,但无法根据该文本框旁边的按钮弄清楚如何删除文本框

我还需要将所有数据保存到数据库中.
谁能帮忙!

下面是我用来添加文本框的代码,我还需要添加一个删除按钮,并且该删除按钮也应该删除文本框和按钮本身.


Hi,

I need to dynamically add textboxes and for each textbox add delete button besides it which should delete that textbox and then on save button all the data should be available to the controller as i''m using MVC3 Razor view. So I dont have any aspx.cs file i''m using razor view where .cshtml files are used.

I''ve tried using Jquery but I could not delete the textboxes randomly,
I can delete the last added textbox but not able to figure out how to delete a textbox based on a button next to that textbox

Also i need to save all the data into database.
Can anyone please help!!

Below is the code which i''m using to add textbox i need to add a delete button as well and also that delete button should delete the textbox and buttton itself.


$("#addButton").live('click', function () {

            if (counter > 21) {
                alert("Only 21 textboxes allow");
                return false;
            }

            var $ctrl1 = $('<p class="list">');
            var $ctrl2 = $('<input/>').attr({ type: 'text', name: 'mediaVehicle' + counter, id: 'mediaVehicle' + counter });
            var $ctrl3 = $('</p>');
            $("#MediaVehiclesGroup").append($ctrl1);
            $("#MediaVehiclesGroup").append($ctrl2);
            $("#MediaVehiclesGroup").append($ctrl3);

            counter++;
        });

推荐答案

(" ).live( click',函数(){ 如果(计数器> 21){ alert(" ); 返回 false; } var
("#addButton").live('click', function () { if (counter > 21) { alert("Only 21 textboxes allow"); return false; } var


ctrl1 =
ctrl1 =


( ' < p class ="list">');; var
('<p class="list">'); var


这篇关于动态添加Texbox并随机删除任何texbox,并将所有数据保存在数据库中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆