单击“创建节点”按钮时,如何打开新框架或窗口?我希望新框架包含一个文本字段和下拉菜单,以便用户可以选择一个选项。

<form>
<html>
<body>
  <button onclick="myFunction()">Create node</button><br>
  <br>
  <button onclick="myFunction()">Search node</button><br>
  <br>
  <button onclick="myFunction()">Create Realationship</button><br>
</body>
</html>
</form>


从上面的代码中,我可以创建并单击按钮,但是无法创建新框架,并且我不知道如何为用户提供选择的选项。

最佳答案

我想你的意思是:

var myFunction = function() {
   //create some html elements with the createElement function
    var select = document.createElement("select"),
        input = document.createElement("input");
    var head = document.createElement("h2");
    var option1 = document.createElement("option");
    var option2 = document.createElement("option");

    //change the content of elements
    head.innerHTML = "select and edit option";

    option1.innerHTML = "option 1";
    option2.innerHTML = "option 2";
    //you can add an element to another element with element.appendChild("new child element here")

    select.appendChild(option1);
    select.appendChild(option2);

    //you can set all attributes with element.setAttribute("attribute name", "attribute value")
    input.setAttribute("type", "text");

    //open a window, with no url and a specified width and height
    var w = window.open('', "", "width=600, height=400, scrollbars=yes");

    //again add children elements, but now insert them to the created window which is stored in the 'w' variable (note that it does not replaces the document, it only means that you represent another window)
    w.document.body.appendChild(head);
    w.document.body.appendChild(select);
    w.document.body.appendChild(input);
}


在这里摆弄:http://jsfiddle.net/tkf4cnqo/5/

您还可以加载预定义的url,但要使其动态化将很困难。

我希望这可以帮助你。

关于javascript - 如何使用下拉菜单打开新框架/窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28266224/

10-11 14:39