js最后一个字符串怎么获得(遇到的js数据绑定和字符串截取问题)
js最后一个字符串怎么获得(遇到的js数据绑定和字符串截取问题)$(".markform input.h3").keyup(function(){});ped=$(this).val();""==ped && (ped=$(this).attr("placeholder"))$(".mod-mark h3").html(ped);
js
下边这个思路就是光标在input的时候把input的值或者placeholder属性的值给另一个标签;
var ped;
$(".markform input.h3").focus(function(){
ped=$(this).val();
""==ped && (ped=$(this).attr("placeholder"))
$(".mod-mark h3").html(ped);
});
$(".markform input.h3").keyup(function(){
var valh3=$(".markform input.h3").val();
$(".mod-mark h3").html(valh3);
});
$(".markform input.h3").blur(function(){
$(".mod-mark h3").html(ped);
});
还有一个思路差不多的就是多了一个点击的步骤:
$(".l").click(function(){
$(this).addClass("focus");
$(this).siblings().removeClass("focus");
//获取选择的图片路径
var ped2;
ped2=$(this).children('input').val();
""==ped2 && (ped2=$(this).children('input').attr("placeholder"))
$(".mod-mark p span").html(ped2);
// $(".mod-mark p span").html($(this).children('input').val());
$(this).children('input').keyup(function(){
$(".mod-mark p span").html($(this).val());
console.log($(this).val());
});
$(this).children('input').blur(function(){
$(".mod-mark p span").html(ped2);
});
});
还遇到了rgb值转换十六进制的:
function RGBToHex(rgb){
var regexp = /[0-9]{0 3}/g;
var re = rgb.match(regexp);//利用正则表达式去掉多余的部分,将rgb中的数字提取
var hexColor = "#"; var hex = ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'A' 'B' 'C' 'D' 'E' 'F'];
for (var i = 0; i < re.length; i ) {
var r = null c = re[i] l = c;
var hexAr = [];
while (c > 16){
r = c % 16;
c = (c / 16) >> 0;
hexAr.push(hex[r]);
} hexAr.push(hex[c]);
if(l < 16&&l != ""){
hexAr.push(0)
}
hexColor = hexAr.reverse().join('');
}
//alert(hexColor)
return hexColor;
}
//下边调用rgb转换函数
var color1=$(this).children("h3").css("color");
color1=RGBToHex(color1);
另外发现对字符串截取的时候,有时候电脑端支持,手机端有时候不支持,
对字符串的截取常用:substring( startindex endindex) substr(startindex length) slice(startindex endindex);
用substring 时候电脑端没问题,手机微信中有问题,后来用slice(startindex endindex);都可以了