两个输入,生成链接

时间:2017-07-04 04:15:12

标签: input hyperlink field generator

尝试从两个输入字段,标题和链接文本生成链接。它应该在您键入时生成。这是我到目前为止所得到的:

<input type="text" id="title" value="" placeholder="Paste title"/><br>
<input type="text" id="link" value="" placeholder="Paste link"/>    
<br>
<br>

Title: <span id="text_1"></span>
<script type="text/javascript">
$("#title").keyup(function() {
  $("#text_1").text($("#title").val());
})
</script>
<br>
<br>

Link <span id="text_1_link"></span>
<script type="text/javascript">
$("#link").keyup(function() {
  $("#text_1_link").text($("#link").val());
})
</script>
<br>
<br>

Combined here:

1 个答案:

答案 0 :(得分:0)

我认为你喜欢这样的事情:

&#13;
&#13;
$("#link").keyup(function() {
  $("#text_1_link").text($("#link").val());
  $(".link").attr('href',$("#link").val());
  
})
$("#title").keyup(function() {
  $("#text_1").text($("#title").val());
  $(".link").text($("#title").val());
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="text" id="title" value="" placeholder="Paste title"/><br>
<input type="text" id="link" value="" placeholder="Paste link"/>    
<br>
<br>

Title: <span id="text_1"></span>
<br>
<br>

Link <span id="text_1_link"></span>
<br>
<br>

Combined here: <a href="#" class="link"></a>
&#13;
&#13;
&#13;