来自文本输入的动态 link

Dynamic link from a text input

我有一个文本输入框和下面的 link(我使用 Webix) 我想要做的是在文本字段中输入 link(IP 地址)的一部分,并将此地址应用于 link.

我试过了

elements:[
    { view:"text", label:'IP', name:"IPname", id:"IPid", value:"127.0.0.1" },
    { view:"template", height: 30, 
     template:"<span><a href='' onclick='"+window.open($$("IPid").getValue()+"'>Test link</a></span>" 
    }        
],

但是这个写法不起作用(实际上,报错"IPid is undefined")

我的代码Here

有什么办法吗?

关于你 错误 "IPid" 未定义 发生是因为声明 id 没有与任何控件一起使用,可能是你拼写错误。如果一切正常,请尝试此代码

 $("#YoutextBoxID").val();

并将其粘贴到您发送进一步请求的位置 activity 像这样 click='"/*+window.open($("#YoutextBoxID").val()*/+"'

奇怪的问题,我对 webix 不是很熟悉,但是将 window.open 放在一个函数中是可行的。还要记住,正确的属性是 'onclick' 而不是 'click' 并且缺少括号。也修复了它们,检查一下:http://webix.com/snippet/e4e236b9

webix.ui({
  rows:[
    {
      id:"form1", view:"form", scroll:false,            
      elements:[
        { view:"text", label:'IP', name:"IPname", id:"IPid", value:"127.0.0.1" },
        { view:"template", height: 30, 
         template:"<span><a href='' onclick='fixLink()'>Test link</a></span>" 
        }        
      ],
      width: 320,
      elementsConfig:{        
        labelPosition: "top",        
      }
    }       
  ]    
});

<script>
function fixLink(){  
  window.open('http://'+$$("IPid").getValue());
}
</script>

请试试这个,我不知道这是否对你有帮助,如果我错了请纠正我。

webix.ui({
    rows:[
        {
            id:"form1", view:"form", scroll:false,            
            elements:[
                { view:"text", label:'IP', name:"IPname", id:"IPid",   value:"127.0.0.1" },
                { view:"template", height: 30, 
                    template:"<span><a href='' id='anId' click='"/*+window.open($$("IPid").getValue()*/+"'>Test link</a></span>" 
                }        
            ],
            width: 320,
            elementsConfig:{
                labelPosition: "top",        
            }
        }       
    ]    
});

func1();
function func1() {
    document.getElementById("anId").setAttribute("href",$$("IPid").getValue());
    var abc = document.getElementById("anId").getAttribute("href");
}
window.onload=func1;