console
function paste() {
var Url2 = document.getElementById("myInput");
Url2.select();
document.execCommand("Paste")
}
function myFunction() {
var x = document.getElementById("myInput").value;
document.getElementById("myOut").value = toHump(x);
copy();
}
function toHump(name) {
name = name.charAt(0).toLowerCase() + name.slice(1);
return name.replace(/\ (\w)/g, function(all, letter) {
return letter.toUpperCase();
});
}
function copy() {
var Url2 = document.getElementById("myOut");
Url2.select();
try {
if (document.execCommand('copy', false, null)) {
document.execCommand("Copy");
document.getElementById("demo").innerHTML = "<div style='color:#5fb878'>已复制好,可贴粘。</div>";
} else {
document.getElementById("demo").innerHTML = "<div style='color:#F00'>复制失败,请手动复制</div>";
}
} catch(err) {
document.getElementById("demo").innerHTML = "<div style='color:#F00'>复制失败,请手动复制</div>";;
}
}
function empVal(){
document.getElementById("myInput").value =''
}
<p>
在线js空格 转驼峰命名
</p>
原始:
<input type="text" id="myInput" oninput="myFunction()" style="width:260px">
<button onclick="paste()">
粘贴
</button>
<button>
复制
</button>
<button onclick="empVal()">
清空
</button>
<br>
结果:
<input type="text" id="myOut" oninput="" style="width:260px">
<button>
粘贴
</button>
<button>
复制
</button>
<button>
清空
</button>
<p id="demo">
</p>