在使用 jQuery 发布之前通过链接单击填充表单

发布于 2024-09-13 21:42:03 字数 1103 浏览 0 评论 0原文

我正在使用 JQTouch 构建一个小型网站,我遇到的第一个问题是表单。

我有一个表单

<form action='action.php' class='jqt' id='ajax_post' method='post' name='pform'>

(当我尝试使用 document.pform 访问它时,其中 name 属性就在那里),其中有一个 a 的 ul 列表code> 元素如下:

<a class="submit" href="#"  value="somevalue">Text displayed</a>

在表单内部的下方,我放置了一个隐藏的输入字段(因为我只想发布一个值),我的目标是通过单击其中一个链接然后提交来填充它:

<input name='somename' type='hidden' />

提交时,网络服务器报告执行了 POST,并且在页面返回到原始形式之前有一个简短的幻灯片动画。尝试侵入 jqtouch.js 来填充输入字段不起作用(我正在尝试的是 $form.somename.value = $(this).attr('value');submitParentForm() 内的 code>)

CSS 捕获良好,列表显示良好。事实上,如果我删除 submit 类并插入我自己的表单提交覆盖 document.somename.value = %(this).attr('value'); document.pform.submit();,例如,其中一个链接中的 hrefonClick,执行 POST 并显示下一页,尽管是通过重新加载而不是使用 jQTouch 动画,这是我的目标。

我的问题:当我发布一个表单时,当用户单击它时,我想用 a 元素的 value 填充该表单,如何使用 jQTouch 来显示幻灯片动画?

提前致谢。

I'm building a small website with JQTouch and the first problem I've run into yet is with a form.

I have a form

<form action='action.php' class='jqt' id='ajax_post' method='post' name='pform'>

(where the name attribute is there when I tried to access it with document.pform)and within it is a ul list of a elements as follows:

<a class="submit" href="#"  value="somevalue">Text displayed</a>

Underneath, inside the form, I placed a single hidden input field (because I only want to POST one value), where my goal is to populate it by clicking one of the links and then submitting:

<input name='somename' type='hidden' />

On submission, the webserver reports that a POST was performed, and there is a brief slide animation before the page returns to the original form. Trying to hack my way into jqtouch.js to populate the input field doesn't work (where what I'm trying is $form.somename.value = $(this).attr('value'); inside submitParentForm())

The CSS captures well and the list is displayed nicely. In fact, if I remove the submit class and insert my own form submission override with document.somename.value = %(this).attr('value'); document.pform.submit(); inside, for instance, hrefor onClick in one of the links, the POST is performed and the next page is displayed, albeit by reloading and not with a jQTouch animation, which is my goal.

My question: How can I use jQTouch to show a slide animation when I post a form which I want to populate with the value of an a element when a user clicks on it?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倥絔 2024-09-20 21:42:03

我不会提交表单(如果我想使用提交按钮,我会使用 PreventDefault)。我只需使用 $.post() 发布数据,然后使用 jQT.goTo 转到带有幻灯片动画的新页面。新页面位于 jqTouch 中,当然,只是同一文档中的另一个 div,这使得使用 $.post() 回调中的响应可以轻松地在该页面上设置您想要的任何信息。

但这可能不是您想要做的事情的可行解决方案,我不太明白这个问题。

I wouldn't submit the form (if I wanted to use a submit button I'd use preventDefault). I'd just use $.post() to post the data and then jQT.goTo to go to the new page with a slide animation. The new page is in jqTouch, of course, only another div in the same document which makes it easy to set any information you'd like on that page using the response in the callback of $.post().

But this might not be a viable solution to what you're trying to do, I don't really understand the question very well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文