javascript - 模仿表单之外的表单元素的结果

标签 javascript php jquery forms

我有这个表格:

    <form name="dateChooser" id="dateChooser">
        <select name="chooseMonth" id="calChooseMonth">...</select>
        <select name="chooseYear" id="calChooseYear">...</select>
    </form>

因此,在更改 #calChooseMonth/#calChooseYear 时,我将 (this.form) 作为参数传递给函数。控制台日志记录(this.form)给了我这个:

    <form name="dateChooser" id="dateChooser">
        <select name="chooseMonth" id="calChooseMonth">...</select>
        <select name="chooseYear" id="calChooseYear">...</select>
    </form>

enter image description here

我试图在表单之外传递相同的表单数据,所以我不能使用“this”。我试过:

      console.log($("form[name='dateChooser']"));

这会返回表单内容的客观数组,这可以工作,但我将数据发送到的函数是第三方,并且需要格式为的数据

      console.log($('#dateChooser').html());

返回与我的(this.form)返回不匹配的原始html

      console.log($('#dateChooser').form);

返回 undefined 不是一个函数。有点希望事情就这么简单。

最佳答案

您想要使用.get()方法。

$("#dateChooser").get(0)

.html() 返回给定选择器包含的 HTML。

关于javascript - 模仿表单之外的表单元素的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25068093/

相关文章:

javascript - 如何使链接充当文件输入

javascript - json 加载后切换 li 不起作用?

php - MySQL 函数 Create Table 给我一个语法错误

php - 帮助带括号的sql查询

JavaScript-jQuery-PHP : Display specific time dynamically in my datetimepicker from the database

javascript - 如何将页面滚动链接到 div 元素滚动?或者如何使用页面滚动来滚动 div 元素?

javascript - 使用 javascript 中的 setInterval 函数在控制台中打印未定义的原型(prototype)

用链接标签替换 "some words"的 php 正则表达式,但应该排除链接标签内的 "some words"

javascript - JQuery click 只记录第一次点击,不记录后续点击

javascript - Angularjs 文本/数据未显示