简体   繁体   English

来自文本输入的动态链接

[英]Dynamic link from a text input

I have a text input and a link below it (I use Webix) What I want to do is to enter a part of a link (IP address) to the text field and apply this address to a link. 我有一个文本输入和一个下面的链接(我使用Webix),我想做的是输入文本字段的链接(IP地址)的一部分并将此地址应用于链接。

I tried 我试过了

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>" 
    }        
],

But this notation doesn't work (actually, gives an error "IPid is undefined") 但是这种表示法不起作用(实际上,出现错误“ IPid未定义”)

My Code Here 我的代码在这里

Is there any way to do this? 有什么办法吗?

Strange issue, I'm not very familiar with webix, but putting the window.open in a function worked. 奇怪的问题,我对webix不太熟悉,但是将window.open放在一个函数中起作用。 Also have in mind that the correct attribute is 'onclick' not 'click' and that a parenthesis was missing. 还请记住,正确的属性是“ onclick”而不是“ click”,并且缺少括号。 Fixed them too, check it out: http://webix.com/snippet/e4e236b9 也修复了它们,请查看: 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>

Please try this, I don't know whether this will help you or not, please correct me if i am wrong. 请尝试一下,我不知道这是否对您有帮助,如果我错了,请纠正我。

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;

About you Error "IPid" is undefined occur because the declare id is not using with any control may be you do spelling mistake. 关于您错误“ IPid”是未定义的,因为声明ID未与任何控件一起使用,可能是您拼写错误。 If every this is fine try this code 如果一切正常,请尝试以下代码

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

and paste it where your request send for further activity Like This click='"/*+window.open($("#YoutextBoxID").val()*/+"' 并将其粘贴到您的请求发送以进行进一步活动的位置,例如: click='"/*+window.open($("#YoutextBoxID").val()*/+"'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM