js根据name输出跟name有关的数据方法怎么实现

JavaScript05

js根据name输出跟name有关的数据方法怎么实现,第1张

以下代码可以实现:varname=$("input[name='name']")。val();varage=$("input[name='age']")。val();varsex=$("input[name='sex']:checked")。val()。

putArr=document.getElementsByClassName() ()("input的class名称")

putArr=document.getElementById()("input的id")

putArr=document.getElementsByName("input的名称")

for(var i=0i<inputArr.lengthi++){

alert(inputArr[i].id)

}

扩展资料

Document 对象事件

1、onactivate,当对象设置为活动元素时触发。

2、onbeforeactivate,对象要被设置为当前元素前立即触发。

3、onbeforecut,当选中区从文档中删除之前在源对象触发。

4、onbeforedeactivate,在 activeElement 从当前对象变为父文档其它对象之前立即触发。

5、onbeforeeditfocus,在包含于可编辑元素内的对象进入用户界面激活状态前或可编辑容器变成控件选中区前触发。

6、onbeforepaste,在选中区从系统剪贴板粘贴到文档前在目标对象上触发。

7、onclick,在用户用鼠标左键单击对象时触发。

8、onmouseover,鼠标指针移到对象时触发

9、onmouseout,鼠标指针移出对象时触发 

Document 对象方法

1、attachEvent,将指定函数绑定到事件,以便每当该事件在对象上触发时都调用该函数。

2、clear,目前尚未支持。

3、close,关闭输出流并强制将数据发送到显示。

4、createAttribute,以指定名称创建 attribute 对象。

5、createComment,以指定数据创建 comment 对象。

6、createDocumentFragment,创建一个新文档。

7、createElement,为指定标签创建一个元素的实例。

8、createEventObject,生成当使用 fireEvent 方法时用于传递事件相关信息的 event 对象。

9、createStyleSheet,为文档创建样式表。

10、createTextNode,从指定值中创建文本字符串。

11、detachEvent,从事件中取消指定函数的绑定,这样当事件触发时函数就不会收到通知了

12、write(),动态向页面写入内容

13、createElement(Tag),创建一个html标签对象  

14、getElementById(ID),获得指定ID值的对象  

15、getElementsByName(Name),获得指定Name值的对象

示例

下面的例子使用了 document 对象检查文档标题并在消息框中显示该标题(如果非空)。

if (document.title!="") alert("标题为 " + document.title)下面的例子演示了在浏览器的状态栏上显示鼠标当前位置的事件句柄函数,所得位置相对于文档的左上角。

<HTML>

<HEAD>

<TITLE>报告鼠标移动</TITLE>

<SCRIPT LANGUAGE="JScript">

function reportMove(){

window.status = "X=" + window.event.x + " Y=" + window.event.y

}

</SCRIPT>

<BODY onmousemove="reportMove()">

<H1>欢迎!</H1>

</BODY>

</HTML>

参考资料:百度百科:document对象

html:

<input type="text" id="txt_name" name="txt"/>

JS中 input中两种方法实现,通过name值取得id值

js:

1.var input_txt=$("input").attr("name")

if(input_txt=='txt'){

console.log($("input").attr("id"))

}

2.var id=[]

$(input[name]).each(function(){

id.push({name:this.name,id:this.id})

})

console.log($(input[name=txt]).attr('id'))