【问题标题】:Retrieve an input value from a node从节点检索输入值
【发布时间】:2017-12-16 08:39:06
【问题描述】:

我有这个代码:

<div id="tree">
    <ul>
        <li>
            ind impianto 1
            <ul>
                <li>
                    <input id="crea1" name="crea1" type="text" placeholder="anno">
                    <button onClick="creaquestionario(1)">crea</button>
                </li>
            </ul>
        </li>
    </ul>
</div>

如果我尝试在函数creaquestionario() 中使用var anno=$('#crea1').val(); 检索输入值,它会返回一个空字符串。 树的声明是:

$("#tree").fancytree({
    keyboard: false,
    activate: function(event, data) {
        var node = data.node;
        if (node.data.href) {
            eval(node.data.href);
        }
    },
});

我想创建一个按钮,该按钮调用一个具有输入值和一个值的函数(代码是在 php 脚本中创建的)

【问题讨论】:

  • 因为&lt;input id="crea1" name="crea1" type="text" placeholder="anno"&gt; 没有价值。
  • 变量crea1的值在哪里设置?
  • 用户在输入框中插入值,当点击按钮时我想检索 te 值插入

标签: javascript php jquery fancytree


【解决方案1】:

试试这样的(这段代码对我有用,希望对你有帮助)

// 1. Render hidden form fields 
$("#tree").fancytree("getTree").generateFormElements(true, false);

// 2. After this, you can access them using normal JQuery (i.e. select on class names or IDs). Shown here iterating all input elements,
$("input").each(function (index, element) {
  // do something with the input, read the value, whatever:
  var s = $(this).val();
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多