从jQuery中的另一个页面检索按钮值

时间:2014-02-05 15:30:22

标签: jquery ajax forms button

我有以下jQuery为JSON数组中的每个条目创建一个div元素

var res = $('#videoContainer');
$.each(msg, function (index, e) {
    var newdiv = $('<form action = "makeNotes.html" method = "get"><button name="video"                
      value=' + e.ID + '><div class="videos">' + e.ID + e.Name + e.Directory + '<div></button></form>');
    res.append(newdiv);
});

在操作页面“makeNotes.html”中,我想获取已单击按钮的值(e.ID)。

有人可以帮我用JQuery来做这件事吗?请原谅我对jQuery的不了解,如果我也错误地完成了上述代码,请提出建议。

由于

2 个答案:

答案 0 :(得分:0)

使用.on()

res.on('click', 'form[action="makeNotes.html"] button', function () {
    alert(this.id);
});

Event Delegation

Attribute Equals Selector [name="value"]

答案 1 :(得分:0)

我不认为这是一个jQuery问题 - 它听起来像是一个HTML表单问题。

我建议在表单中创建第二个输入元素:<input type='hidden' name='videoId' value='" + e.ID + "'/>

此外,您可能需要<button ...>

而不是<input type='submit' ...>