【问题标题】:getting values of options from select in clojure从clojure中的select中获取选项值
【发布时间】:2015-11-09 08:51:26
【问题描述】:

我想知道如何编写这个 javascript 函数来从 Clojure 函数中的选择选项中获取值。

<select id="namelist">
  <option value="1">test1</option>
  <option value="2" selected="selected">test2</option>
  <option value="3">test3</option>
</select>

我想在 clojurescript 中编写下面的 javascript 函数

var e = document.getElementById("namelist");
var strUser = e.options[e.selectedIndex].text;

请告诉我 clojurescript 中对应的代码是什么

【问题讨论】:

  • 我试过这个(defn get-value-by-id [id] (->> id (.getElementById js/document) .-value))

标签: javascript clojure clojurescript


【解决方案1】:

成绩单是:

(let [e (js/document.getElementById "namelist")]
  (.-text (aget (.-options e) (.-selectedIndex e))))

【讨论】:

    猜你喜欢
    • 2021-05-23
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    相关资源
    最近更新 更多