Domanda

voglio aggiungere H323: collegamenti numero di stile per i numeri di contatto HighRise, in modo che gli utenti possono fare clic su un collegamento per comporre il telefono IP ...

il codice HTML che sto guardando è:

<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>

e fondamentalmente voglio tirare fuori il numero che si trova in un td e che inizia con 44, striscia fuori gli spazi e bastone in un link all'interno della campata che ha un href come

h323:4411231231312  

vale a dire. è escludendo il 0 tra parentesi.

Qualsiasi aiuto sarebbe greatfully ricevuto a uno dei seguenti.

(1) Come abbino il td contenente + \ d \ d numeri? (2) Come faccio a utilizzare i selettori di escludere l'intervallo quando ricevo il numero dal TD (3) Cosa regex devo usare per la pulizia il numero per la href?

È stato utile?

Soluzione

Questo dovrebbe essere vicino a quello che ti serve.

$('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);
    }
});

Una parola di cautela, però, se il contenuto di un span inizia con una cifra che sarà incluso nel match; È questa una possibilità che deve essere rappresentato?

Altri suggerimenti

Ecco lo script GreaseMonkey finale - potrebbe essere utile per qualcuno ...

// ==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);
       }
   });

}

})();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top