如何在选择选项中返回数据 [英] How can I return the data in select option

查看:56
本文介绍了如何在选择选项中返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个问题,因为当我保存数据时,我可以得到选项框的值,但是在单击编辑"按钮时,它是相同的.我想做的是它将变成带有值的选项框首先显示

I have an issue here because when I'm saving my data I can get the value of the option box but upon clicking the edit button its the same.. I want to do is it will become the option box with the value showing first

这里是我的小提琴: http://jsfiddle.net/te2wF/32/

这里是我的代码:

function Edit(){
    var par = $(this).parent().parent(); //tr
    var tdName = par.children("td:nth-child(1)");
    var tdAge = par.children("td:nth-child(2)");
    var tdGender = par.children("td:nth-child(3)");
    var tdButtons = par.children("td:nth-child(4)");

    tdName.html("<input type='text' id='txtName' value='"+tdName.html()+"'/>");
    tdAge.html("<input type='text' id='txtage' value='"+tdAge.html()+"'/>");
    tdGender.html(tdGender.html());
    tdButtons.html("<input type='button' value = 'Save' class='btnSave'/><input type='button' value='Delete' class='btnDelete'/>");

    $(".btnSave").bind("click", Save);
    $(".btnEdit").bind("click", Edit);
    $(".btnDelete").bind("click", Delete);
};

推荐答案

正在运行的演示

解决的几个问题:

1..更新了Edit功能,提供了一个选择选项,可编辑最后一次选择的选择.

1. Updated Edit function to provide a select option to edit the selection with last selection selected.

function Edit() {
        var par = $(this).parent().parent(); //tr
        var tdName = par.children("td:nth-child(1)");
        var tdAge = par.children("td:nth-child(2)");
        var tdGender = par.children("td:nth-child(3)");
        var tdButtons = par.children("td:nth-child(4)");

        tdName.html("<input type='text' id='txtName' value='" + tdName.html() + "'/>");
        tdAge.html("<input type='text' id='txtage' value='" + tdAge.html() + "'/>");
        if(tdGender.html().toLowerCase() == "female") {
            tdGender.html("<select class='gender'><option></option><option>Male</option><option selected>Female</option></select>");
        } else {
            tdGender.html("<select class='gender'><option></option><option selected >Male</option><option >Female</option></select>");
        }
        tdButtons.html("<input type='button' value = 'Save' class='btnSave'/><input type='button' value='Delete' class='btnDelete'/>");

        $(".btnSave").bind("click", Save);
        $(".btnEdit").bind("click", Edit);
        $(".btnDelete").bind("click", Delete);
    };

2..您的代码无法找到isNumberKey函数.因此,我将其移出了范围,以便可以从任何地方访问它.

2. Your code was not able to find isNumberKey function. So, I moved it outside the scope so that its accessible from everywhere.

3..在您的Add函数中,select标记还包含一个>.在我的代码中将其删除.

3. In your Add function, the select markup contained an additionally >. Removed it in my code.

这篇关于如何在选择选项中返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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