首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HighRise jQuery解析

HighRise jQuery解析
EN

Stack Overflow用户
提问于 2009-10-01 14:14:06
回答 2查看 291关注 0票数 0

我想添加h323:数字样式的链接到HighRise联系号码,以便用户可以单击链接拨打IP电话...

我看到的html是:

代码语言:javascript
复制
<table>
  <tbody>
    <tr>
      <th>Phone</th>
      <td>+44 (0)1123 1231312<span>Work</span></td>
    </tr>
    <tr>
      <th></th>
    <td>+44 (0)777 2342342<span>Other</span></td>
    </tr>
  </tbody>
</table>

基本上,我想取出td中以+44开头的数字,去掉空格并插入跨度内的一个链接,该链接的href类似

代码语言:javascript
复制
h323:4411231231312  

即去掉括号中的0。

任何帮助都将受到以下任何一项的极大欢迎。

(1)如何匹配包含+\d\d数字的td?(2)当我从td中获取数字时,如何使用选择器排除跨度?(3)我应该使用什么正则表达式来清除href的数字?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-10-01 14:24:48

这应该接近您需要的内容。

代码语言:javascript
复制
$('tbody td').each(function() {
    // match a sequence of digits, parentheses and spaces
    var matches = $(this).text().match(/[ \d()]+/);

    if (matches) {
        // remove the spaces and stuff between parentheses
        var href = 'h323:' + matches[0].replace(/\s|\(.*?\)/g, '');
        var link = $('<a/>').attr('href', href);

        $('span', this).append(link);
    }
});

但是,需要注意的是,如果span的内容以数字开头,它将被包括在匹配中;这种可能性需要考虑吗?

票数 3
EN

Stack Overflow用户

发布于 2009-10-06 12:15:25

这是最终的GreaseMonkey脚本--可能对某些人有用...

代码语言:javascript
复制
// ==UserScript==
// @name          HighRise Dialler
// @namespace     
// @description   Adds a CALL link to HighRise Contacts.
// @include       https://*.highrisehq.com/*
// @require       http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==

(function(){

GM_xmlhttpRequest({
   method: "GET",
   url: "http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js",
   onload: run
});

function run(details) {

   if (details.status != 200) {
       GM_log("no jQuery found!");
       return;
   }

   eval(details.responseText);
   var $ = jQuery;

   //do something useful here....

   $('table td').each(function() {
       var matches = $(this).text().match(/^\+*?[\d\(\) ]+/);

       if (matches) {
         var href = 'h323:' + matches[0].replace(/\+44|\+|\s|\(|\)/g, '');
         var link = $(' <a>CALL<a/>').attr('href', href);
         $(this).find('span').append(link);
       }
   });

}

})();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1504215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档