var id=Math.random();
//var id="mm"
$('body').html('<div id='+id+'>hha</div>');
$('#'+id).removeAttr('id');
var id=Math.random();
//var id="mm"
$('body').html('<div id='+id+'>hha</div>');
$('#'+id).removeAttr('id');
数字是不允许作为选择器使用的,你去控制台看报错
还有就是你去控制台
document.querySelector('#1')
// Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#1' is not a valid selector.
可以使用原生的另一个方法试下,
document.getElementById('#1')
//null
你改写成 getElementById 试下
生成随机字符串:
randomString(6);
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';//可以自定义
var maxPos = $chars.length;
var pwd = '';
for(i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
1 回答851 阅读✓ 已解决
1 回答1.1k 阅读
2 回答773 阅读
2 回答617 阅读
2 回答601 阅读
1 回答681 阅读
2 回答521 阅读
因为生成的id中包含小数点,这个刚好与class选择器冲突了,不建议在id中包含小数点,这个需要这样改才能选择到这个元素