如何在innerHTML中添加呼叫电话号码链接

时间:2015-10-12 13:33:59

标签: javascript html

我正在尝试使用<a href>内的innerHTML标记添加特定于通话的电话号码。我试过双引号和单引号。

第一个案例 根本没有解雇。

确实出现了

第二案例 ,但是当点击电话号码而不是拨号时,它会关闭。

 var popDiv = document.createElement('span');
           popDiv.setAttribute('class', 'popDiv');
           popDiv.innerHTML ="It seems you are looking for: " + "<span style='color:#FF0000'>" + getTitle + "</span>" + "<br />" + "Why don't you call me?" + "<a href='tel:01234567890'>01234 567 890</a>";

请找到JSFiddle

的链接

有谁知道可能的解决方案是什么?

2 个答案:

答案 0 :(得分:1)

您需要查看EditText rb = new EditText(this); // Field ID list is a hashmap of unique integer IDs with string keys rb.setId(fieldIDList.get("byField")); linearLayout.addView(rb); // This is a test variable that confirms the ID has been set in debugging int testVar = rb.getId(); 事件的mouseup以及target,然后才能删除h1。这应该有效:

popDiv

更新了 jsFiddle

答案 1 :(得分:0)

试试吧:

 var popDiv = document.createElement('span');
           popDiv.setAttribute('class', 'popDiv');
           popDiv.innerHTML ="It seems you are looking for: " + "<span style='color:#FF0000'>" + getTitle + "</span>" + "<br />" + "Why don't you call me?" + "<a href=\"tel:01234567890\">01234 567 890</a>";

并确保你没有这样的元:

<meta name = "format-detection" content = "telephone=no">