js 问题

WBOY
WBOYOriginal
2016-06-23 13:43:58877browse

<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>


this.name 取不到 select name ?帮忙


回复讨论(解决方案)

<option value = 1>test</option>

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

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

Statement:
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