js 问题

WBOY
Release: 2016-06-23 13:43:58
Original
850 people have browsed it

<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script><div class="tables"><select name="one" id="one">	<option value = 1>test</option>	<option value = 2>test1</option></select><select name="two" id="two">	<option value = 1>haha1</option>	<option value = 2>haha1</option></select><button onclick="save()">保存</button></div><script type="text/javascript">	function save(){		$(".tables select option:selected").each(function(){        var signSelect = this.name+"="+this.value;         alert(signSelect);            });	}</script>
Copy after login


this.name 取不到 select name ?帮忙


回复讨论(解决方案)

<option value = 1>test</option>
Copy after login

因为each中,this是指option。而option没有name。

改成这样就可以了。
var signSelect = this.parentNode.name+"="+this.value; 
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template