该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
1、实现一个函数,判断输入是不是回文字符串。
function palindrome(string $str):bool
{
if('' == $str) return false;
for($i=0,$j=mb_strlen($str,'UTF-8') -1;$i<=$j;$i++,$j--){
if(mb_substr($str,$i,1,'UTF-8') != mb_substr($str,$j,1,'UTF-8')) return false;
}
return true;
}
2、两种以上方式实现已知或者未知宽度的垂直水平居中。
.al{
display: flex;
align-items: center;
justify-content: center;
}
.al{
display: inline-block;
width:100px;
height:100px;
padding:44px;
font-size:12px;
line-height:12px;
box-sizing: border-box;
}
3、实现效果,点击容器内的图标,图标边框变成border 1px solid red,点击空白处重置。
$('body').on('click','.al > a',function(){
$(this).css('border','1px solid,red');
return false;
});
$('body').on('click','.al',function(){
$(this).child('a').css('border','');
return false;
});
4、请简单实现双向数据绑定mvvm。
var obj = {};
Object.defineProperty(obj ,'data',{
get:function(){ return data; },
set:function(newValue){
data=newValue;
document.getElementByID('abc').innerText(netValue);
} });
obj.data = '12121212';
5、实现Storage,使得该对象为单例,并对localStorage进行封装设置值setItem(key,value)和getItem(key)
var st = function (){};
st.prototype.set = function (key,val) {
window.localStorage.setItem('st_v1_' + key,val);
};
st.prototype.get = function (key) {
return window.localStorage.getItem('st_v1_' + key);
};
var sl = (function () {
var instance;
return function (html) {
if (!instance) {
instance = new st();
}
return instance;
}
})();