简体   繁体   English

尝试获取已通过下拉选择项更新的字段的文本值

[英]Trying to get the text value of a field that has been updated by a dropdown selection

(JS Fiddle full code is below) (下面是JS Fiddle的完整代码)

I am selecting a value from a dropdown which then based on selection will update the next table 'td' with a value. 我正在从一个下拉列表中选择一个值,然后基于选择将使用值更新下一个表“ td”。 I am then looping through the table 'tr' to get a ";" 然后,我遍历表'tr'以获取“;” separated list of all the values 所有值的分隔列表

In my fiddle example, I have simplified it to 2 columns where if you select "1" from the dropdown, the next field is updated with 10 and then the next row, the same 在我的小提琴示例中,我将其简化为2列,如果您从下拉列表中选择“ 1”,则下一个字段将更新为10,然后下一行更新,相同

My goal is to get a list of the values in the table 我的目标是获取表中值的列表

For Example 1;10
            2;8

For some reason, I am looping through the table: "Get Data Button initiates loop") 出于某种原因,我遍历该表:“获取数据按钮启动循环”)

$(this).find("td").filter(':visible').each(function (index) {
            if (index === 1) {
                if ($(this).find("span").val() != undefined) {
                    values += $(this).find("span").val() + ";";
                }
                if ($(this).find("text").val() != undefined) {
                    values += $(this).find("text").val() + ";";
                }
                if ($(this).find("label").text() != undefined) {
                    values += $(this).find("label").text() + ";";
                }

                if ($(this).find("select option:selected").text() != "") {
                    values += $(this).find("select option:selected").text() + ";";
                }
            }
        });

But whether I use .text(), val(), inner or outerHTML it is always "" 但是,无论我使用.text(),val(),inner还是externalHTML,它始终是“”

Thanks 谢谢

http://jsfiddle.net/motti10/hjdyxv7n/4/ http://jsfiddle.net/motti10/hjdyxv7n/4/

Don't know exactly what the purpose is, but I have the output wanted with this solution: 不知道确切的目的是什么,但是我需要此解决方案的输出:

       if (index === 0) 
       {
            if ($(this).find("span").val()) {
                values += $(this).find("span").val() + ";";
       ....

updated the fiddle as well http://jsfiddle.net/hjdyxv7n/5/ 还更新了小提琴http://jsfiddle.net/hjdyxv7n/5/

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

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