【问题标题】:How get the data of selected option如何获取所选选项的数据
【发布时间】:2019-02-18 23:26:49
【问题描述】:

我正在使用这个插件:

https://www.jqueryscript.net/demo/Drop-Down-Combo-Tree/

我不会得到那个ID,我该怎么办?

没有可用的适当文档。有什么方法可以得到吗?

<input type="text" id="justAnotherInputBox"
 placeholder="Type to filter" ng-change="showSummery(this)"/>



$scope.showSummery = function (data) {
        console.log(data)
};

【问题讨论】:

  • 你想用id做什么?
  • 我想要选择的字段数据,无论它现在有什么id,title

标签: javascript jquery angularjs select


【解决方案1】:

试试这个,

 <input type="text" id="justAnotherInputBox"
     placeholder="Type to filter" ng-change="showSummery()"/>



    $scope.showSummery = function () {
            console.log(document.getElementById("justAnotherInputBox").value)
    };

【讨论】:

    【解决方案2】:

    您可以在&lt;li&gt; 下方的&lt;input&gt; 上放置一个onclick 监听器:

    $('#justAnotherInputBox')
        .parents('div.comboTreeWrapper')
        .find('div.comboTreeDropDownContainer')
        .on('click','li.ComboTreeItemChlid',function() {
       var id=$(this).find('span').attr('data-id');
       /* the rest of your code */
    });
    

    注意错字“ComboTreeItemChlid”。它也在插件中。

    【讨论】:

    • 加载它的工作,但是当我改变它的值时它不会来。
    • 你确定comboTreeWrapper定义好之后再定义监听器吗?
    • 对我来说也是一样,在 onchange 后不工作。
    • prnt.sc/1wkfo1i 这是我的html树。
    【解决方案3】:

    如果你使用底部代码来定义组合树:

        var comboTree2;
     comboTree2 = $('#justAnotherInputBox').comboTree({
            source: dataJson,
            isMultiple: false
        });
    

    然后您可以使用底部代码来获取选定的值 id:

    comboTree2._selectedItem.id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-01
      • 2022-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2019-06-21
      相关资源
      最近更新 更多