【问题标题】:Convert value in text box to href or hyperlink on button click?将文本框中的值转换为单击按钮时的 href 或超链接?
【发布时间】:2017-02-08 22:22:10
【问题描述】:

我需要您的一些专家建议!我整天都在为这个问题苦苦挣扎。

我有这个小提琴:http://jsfiddle.net/fag9n52y/109/

我在小提琴的“HTML”部分评论了脚本的作用以及我的主要问题。

表单的工作原理:

  1. 用户点击“Coordinate1”文本输入。

  2. Google 地图模式弹出窗口启动。

  3. 然后用户在地图上选择一个位置。

  4. 一旦在地图上触发 eventclick,该位置的坐标就会自动插入到文本框中。

  5. 用户点击“继续”按钮。

  6. 结束。

我需要做什么:

  1. 用户点击“Coordinate1”文本输入。

  2. Google 地图模式弹出窗口启动。

  3. 然后用户在地图上选择一个位置。

  4. 一旦在地图上触发 eventclick,该位置的坐标就会自动插入到文本框中。

  5. 用户点击“继续”按钮。

  6. 坐标转换成这个超链接/href:“https://www.google.com/maps/places/ + {VALUE OF COORDINATE1}”。

  7. 结束。

我尝试过的:我尝试过添加这段代码(这不在小提琴中):

function convertToLink() {
  var coor = document.getElementById('Coordinate1');
  var link2 = "https://www.google.com/maps/places";
  var ContinueButton = document.getElementById('Continue1');

  ContinueButton.onclick = function(){
    coor.value = link2 + coor;         
  };                       
};

【问题讨论】:

  • 请点击<>创建minimal reproducible example
  • coor.value = link2 + coor; 这是不正确的。 coor 是一个 html 元素,link2 是一个字符串。所以字面意思是:将 coor 的值设置为字符串加上元素本身。你可能想要coor.value = link2 + coor.value
  • 好的,非常感谢老兄会试一试!
  • 这个link 是怎么回事?
  • @AlessandroMaglioccola 这几乎完全按照我想要的方式工作。唯一的变化是它必须是“place/”而不是“places/”。 (或者对我来说,“地方”不起作用)。现在我需要做这个确切的场景,但使用“继续”按钮。我想我可以从你的代码中工作!非常感谢!

标签: javascript jquery


【解决方案1】:

getElementById() 返回一个 dom 节点,但您需要该节点的值

改变

var coor = document.getElementById('Coordinate1');

var coor = document.getElementById('Coordinate1').value;

【讨论】:

  • $("#Coordinate1").val()
猜你喜欢
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-26
  • 2017-01-09
  • 2011-07-10
相关资源
最近更新 更多