隐藏电话号码的最后一位数字,如99XX XXX XXX php或jquery

时间:2013-12-02 12:00:29

标签: php jquery ajax

我有这段代码输出var $phone

<span class="row_value phone"><?php echo $this->items->phone; ?></span>

Wich输出:9999 999 999.我希望它输出99XX XXX XXX并在电话号码下方显示一个链接,显示“显示电话号码”,然后点击转为9999 999 999.

2 个答案:

答案 0 :(得分:0)

Try this...
<script language="javascript" type="text/javascript">


function doChange(){

var pass= '';

var special = "xxxxxx";


    s = document.randform.name.value;
    var string_length = s.length-2;
    pass +=s.substring(0,2);
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * special.length);
        pass += special.substring(rnum,rnum+1);
    }

    document.getElementById('dyn').innerHTML = pass;
    document.getElementById('dyn').style.color = 'red';
}
function doChange2(){

    document.getElementById('dyn').innerHTML = s;
    document.getElementById('dyn').style.color = 'blue';
}

</script>
</head>
<body>
<form name="randform">
<input type='text' name='name' value='' /> <i id='dyn' onClick="doChange2();">Hello</i>
<input type="button" value="Create number" onClick="doChange();">&nbsp;

</form>

答案 1 :(得分:0)

试试这个......

<强> PHP

<?php
    $ph  = $this->items->phone;
    $ph1 = substr($ph,0,2);
    $ph2 = substr($ph,1,strlen($ph));
?>
    <span class="row_value phone"><?php echo $ph1; ?><span id="phone-x" data-data="<?php echo $ph2; ?>"><?php echo preg_replace("/[0-9]/","X",$ph2); ?></span></span>
    <button id="show_ph">show phone number</button>

<强>的jQuery

$(document).ready(function() {
  $("#show_ph").click(function() {
    var data = $("#phone-x").html();
    var adata = $("#phone-x").attr("data-data");        
    $("#phone-x").html(adata);
    $("#phone-x").attr("data-data",data);
  })
})

Example