浅谈javascript中createElement事件
createElement是HTML中应用W3CDOM对像模型建立子节点也就是子元素的概念
<script>
window.onload=function(){
varinput =document.createElement('input');
varbutton=document.createElement('input');
input.type='text';
input.id='text';
input.value='1';
button.type='button';
button.value='逐加';
button.style.width='40px';
button.style.height='23px';
document.body.appendChild(input);
document.body.appendChild(button);
button.onclick=function(){
varvalue=input.value;
input.value=value*1+1;
}
}
</script>
注:value其实是一个字符,如果将input.value=value*1+1;换成input.value=value+1;则结果会出现111111,他是不断以字符形式加1的,所以这时候value*1的就能将value值转换成Int型了。
总结:
要最终解决createElement方法的兼容性问题,还是要注意判断浏览器,针对IE可以使用其特有的通过为createElement传入一段合法的HTML代码字符串作为参数的方法,非IE浏览器仍然使用W3C规范的标准方法。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下