<script>
$ (function () {
var text;
$ (". Pos span"). each (function () {
Text = $ (this). Text (). Trim ();
if (text== "set as Default") {
$ (this). CSS (' Display ', ' none ');
}
});
$ (". Pos"). MouseOver (function () {//mouse move in Display effect
Text = $ (this). Find (' span '). Text (). Trim ();
if (text== "set as Default") {
$ (this). Find (' span '). CSS (' Display ', ');
}
}). mouseout (function () {//mouse out vanishing effect
Text = $ (this). Find (' span '). Text (). Trim ();
if (text== "set as Default") {
$ (this). Find (' span '). CSS (' Display ', ' none ');
}
});
});
function deform (obj) {
var id = obj.id
var text = $ ("#" +id). Text (). Trim ();
if (text== ' Set as Default ') {
Get Data ID
var addressid = Id.replace (/[^0-9]/ig, ""); Match get ID
$.post ('/usercenter/setaddress ',
{
Id:addressid
},function (data,textstatus) {
$ (". pos[id!=" +id+ "]"). Find (' span '). Text ("Set as Default"). CSS (' Display ', ' none ');
$ ("#" +id). Find (' span '). Text ("Default address");
});
}
}
<TD width= "class=" pos "onclick=" deform (This) "Id= ' def_<?php echo $val [' id ']?> ' ><span style= ' Cursor:pointer "><?php echo $val [' default_a '] = = 1?" Default Address ":" Set as Default "?></span></td>
</script>
//processing default address
Public Function setaddressaction () {
if (isset ($_server["Http_x_requested_with"]) && Strtolower ($_server["Http_x_requested_with"]) = = "XMLHttpRequest") {//Ajax request Processing method
$id = $_post[' id '];
$model = $this->model (' Address ');
$sql = "Update address set default_a = 0 where default_a = 1";
$model->execute ($sql);
$sql = "Update address set default_a = 1 where id=". $id;
$model->execute ($sql);
echo "Success";
}else{//Normal request Processing
header ("http/1.1 404 Not Found"); exit;
};
}