在下面的示例中,我使用 html id=title
从 this
表单获取 title
。
我该如何做同样的事情,但不使用 ID 而使用名称?
$(document).ready(function(){
$('form').live('submit', function(){
var aform = $('form[name="create_form"]');
// get the entire form
var form = $(this);
// get form title field by ID
var title = this.elements.title.value;
// get selected radio button using name instead if ID
var type = $(this).find('input:radio[name="ctype"]:checked').val() || '';
alert(title);
对于单选按钮,它是通过名称获取的,但我不知道如何将该语法转换为正常形式字段
<input name="title" id="55544_title" type="text" />
最佳答案
在这一行
// get form title field by ID
var title = this.elements.title.value
你不是通过 id 获取它,而是通过 name 属性获取它,所以在某种程度上你已经正确地做到了
关于javascript - 如何通过名称获取 "this"表单内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095642/