Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript从html输入中获取文本,并将其用作另一个html输入的值_Javascript_Html - Fatal编程技术网

javascript从html输入中获取文本,并将其用作另一个html输入的值

javascript从html输入中获取文本,并将其用作另一个html输入的值,javascript,html,Javascript,Html,我有2个html文本输入,所以如果在第一个我把这个链接 会的 现在我希望第二个html输入值是E-LrapH4RtQ <script language="javascript" type="text/javascript"> function removeytb(string) { return string.split('&')[0]; } </script> <input type="text" name="ytbu

我有2个html文本输入,所以如果在第一个我把这个链接

会的

现在我希望第二个html输入值是E-LrapH4RtQ

<script language="javascript" type="text/javascript">
    function removeytb(string) {
        return string.split('&')[0];
    }
</script>

<input type="text" name="ytburl" onblur="this.value=removeytb(this.value);" />
<input type="text" name="name1" value="" />

函数removeytb(字符串){
返回字符串.split('&')[0];
}

这应该有效
var link=www.example.com/idontknowthelink&some?stuff;var splitLink=link.split('&');console.log(splitLink[0]+splitLink[1])将所有链接存储在数组中,然后只需更改链接的src即可

函数removeytb(字符串){
var newUrl=string.split('&')[0];
var name=newUrl.substr(newUrl.lastIndexOf('/')+1);
document.getElementsByName(“名称1”)[0]。值=名称
返回newUrl;
}

好的,这是一个快速修复您正在寻找的问题的方法

职能:

function useInput(InputValue,anotherInput)
  {
   InputValue =  InputValue.split('&')[1];
   if(!InputValue){InputValue='';}; //To avoid showing undefined
   document.getElementById(anotherInput).value=InputValue;
  }
HTML

<input id="myInput" onKeyUp="useInput(this.value,'anotherInput')" value=""/>
<input id="anotherInput" type="input" value="" />


当用户键入时,第一个字段的输入将被捕获、处理并作为另一个输入字段的值放置(动态)

您可以从以下位置更改onblur:

onblur="this.value=removeytb(this.value);"
致:

为了从最后一部分中获取信息,您可以使用和:

因此:

函数removeytb(ele,secondInputName){
//如前所述设置值,但使用元素
ele.value=ele.value.split('&')[0];
//从拆分字符串的ele中获取最后一部分
document.getElementsByName(secondInputName)[0]。value=ele.value.split('/').pop();
}


我在第二次输入的ID中添加了问题的链接,将在一分钟内更新。好的,现在可以了。。我想我也会继续添加字符串拆分方法。。在一小段时间内。这个解决方案现在完全可以工作了。。。所有问题已修复!=)
onblur="removeytb(this, 'name1');"
'https://example.com/E-LrapH4RtQ'.split('/').pop()