【发布时间】:2013-09-11 18:22:46
【问题描述】:
代码:
<form name="newform" action="test.php" method="post" class="form-horizontal input-prepend" id="newform">
<div class="form-group">
<label class="control-label" for="test1">test1</label>
<input type="text" name="test1" class="form-control" id="test1" placeholder="">
</div>
<div class="form-group">
<label class="control-label" for="test2">test2</label>
<input type="text" name="test2" class="form-control" id="test2" placeholder="">
</div>
<div class="form-group">
<label class="control-label" for="test3">test3</label>
<input type="text" name="test3" class="form-control" id="test3" placeholder="">
</div>
<div class="form-group">
<label class="control-label" for="test1">test4</label>
<input type="text" name="test4" class="form-control" id="test4" placeholder="">
</div>
<div class="form-group">
<label class="control-label" for="test5">test5</label>
<input type="text" name="test5" class="form-control" id="test5" placeholder="">
</div>
</form>
为了得到一个输入的值,我们可以使用它的id,例如alert($("#test5").val()),但是在不知道id的情况下如何从表单的开头依次获取输入值输入?
对于我的测试代码,我可以使用代码获得价值:
var value1 = $("test1").val();
var value2 = $("test2").val();
var value3 = $("test3").val();
var value4 = $("test4").val();
var value5 = $("test5").val();
当我们不知道输入的id 时,是否有人对如何获取值有任何想法?
【问题讨论】:
-
你想要什么,一个数组?
-
您想知道输入ID,否则为什么要解析它?当然你不能说一般的对象,但是当涉及到形式时,你是非常具体的。
-
@DavidThomas 如果我真的想分别获取每个值。但是数组也会很好。
-
@Jonast92 在我的测试代码中,所有输入都有 id,但是当我们不知道 id 输入时如何获取它们的值?
-
解释你想要的最终结果,然后我们会想办法帮助你得到它。否则,我们只是在猜测,基于我们所知道的,或者可以,工作。