js动态获取文本框的值

JavaScript012

js动态获取文本框的值,第1张

1.首先通过文本框的使用getelementbyid("idname");方法来获取文本框对象;

2.通过文本框对象来获取文本框的value值

在新打开的页面获得前面文本框内的内容:

window.opener.document.getelementbyid('文本框id').value

拓展资料:

根据指定的

id

属性值得到对象。返回

id

属性值等于

sid

的第一个对象的引用。假如对应的为一组对象,则返回该组对象中的第一个。

百度百科——getelementbyid

首先,只能取出inline的JS内容,如果脚本是通过 src 加载进来的,这个是没办法取出的。

对于 inline 的 JS 内容,高端浏览器使用 textContent ,IE6/7/8 使用 innerText。下面是例子:

<script id="s1">alert(1)</script>

var script = document.getElementById( 's1' )

var text = script.textContent || script.innerText

console.log( text )// output alert(1)