`
web_in
  • 浏览: 13978 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

[Web前端应用]--Javascript最有用的方法之一:document.getElementById() 【难度 ★★★】

阅读更多
document.getElementById("元素的id")是前端开发中最有用的方法之一,是面向对象的体现。其能获取指定id的HTML元素,是Javascript的重要方法。

例如,它能实现对某HTML元素中的值进行修改,或者实现讲Javascript中的变量值传递到HTML表单中,再提交到服务器端的Java或PHP当中,实现前端Javascript变量与后台的Java或PHP变量间的间接传递。

【代码】--按按钮,获取IC的值。
<script language = 'javascript'>
    function changeValue(){
        var obj = document.getElementById("IC")
        obj.value = "高通移动芯片-snapdragon msm8255"
    }
</script>

<input type = "button" value = "点击我获取芯片值" id="IC" name = "IC" onclick = "changeValue()" />

再例
【代码】--控制SELECT标签所选项和只读功能:
document.getElementById("某SELECT标签id").value = 某option中的值
document.getElementById("某SELECT标签id").disabled = true(或者false)

这个功能可以应用在某些表单修改中,不允许用户修改原来已经填写好的部分资料。
分享到:
评论

相关推荐

    repostorie.jar

    javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('0');javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('...

    document.getElementById()

    document.getElementById()对象和使用方法

    javascript常用100语句

    23.弹出输入提示框:window.prompt(); 24.指定当前显示链接的位置:window.location.href= "URL " 25.取出窗体中的所有表单的...29.得到元素的方法:document.getElementById() 30.设置表单中所有文本型的成员的值为空:

    各浏览器对document.getElementById等方法的实现差异解析

    主要是对各浏览器对document.getElementById等方法的实现差异进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助

    javascript 获取iframe里页面中元素值的方法

    IE方法:document.frames[‘myFrame’].document.getElementById(‘test’).value; 火狐方法:document.getElementById(‘myFrame’).contentWindow.document.getElementById(‘test’).value; IE、火狐方法: 代码...

    JS控制HTML元素的显示和隐藏的两种方法

    利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位。  方法一: document.getElementById("EleId").style.visibility=...

    js 密碼 強弱 的三種狀態檢測

    document.getElementById(vImgs).innerHTML="&lt;span style=color:red;font-size:12px&gt;"+16+"&lt;/span&gt;"; } else{ document.getElementById(vImgs).innerHTML="&lt;span style=color:red;font-size:12px&gt;"+(16...

    Javascript的常用语句

    5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value) 6.一个小写转大写的JS: document.getElementById( "output ").value = document.getElementById( "input ").value....

    常用javascript语句大全

    5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或&#118alue) 6.一个小写转大写的&#106s: document.getElementById("output").&#118alue = document.getElementById("input").&...

    JavaScript

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是: document-&gt;html-&gt;(head,body) 4.一个浏览器窗口中的DOM顺序是: window-&gt;(navigator,screen,history,location,document) 5.得到表单中...

    总结常用JavaScript语法107条

    1.输出语句:document.write("") 2.JS中的注释为:// 3.传统的HTML文档顺序是:document-&gt;html-&gt;(head,body) 4.一个浏览器窗口中的DOM顺序是:window-&gt;(navigator,screen,history,location,document) 5.得到表单中元素的...

    107个常用Javascript语句

    5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value) 6.一个小写转大写的JS: document.getElementById( "output ").value = document.getElementById( "input ").value....

    107个javascript语句

    5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID號").name(或value) 6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase...

    107个常用javascript语句

    29.得到元素的方法:document.getElementById() 30.设置表单中所有文本型的成员的值为空: var form = window.document.forms[0] for (var i = 0; i&lt;form.elements.length;i ){ if (form.elements.type == "text"){ ...

    不规则TAB选项卡效果

    &lt;script type=text/javascript&gt; function setTab03Syn ( i ) { selectTab03Syn(i); } function selectTab03Syn ( i ) { switch(i){ case 1: document.getElementById("TabTab03Con1").style....

    JavaScript-js宝典笔学习记.txt

    5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value) 6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase...

    iScroll:一个简单的 purejs 滚动插件

    el: document.getElementById('inner-content'), scrollBar: document.getElementById('tool-bar') }) 比较复杂的例子: iScroll.init({ el: document.getElementById('inner-content2'), direction: 'left...

Global site tag (gtag.js) - Google Analytics