jquery on live(点击)提交表单
我想做的是,我有一个下拉框,可以让我的管理员用户对图片进行 G 级和 X 级评级。一旦他们选择了此选项,我希望提交表格。
我以为这就像发送表单 ID 一样简单,但似乎并非如此。
这是用户需要在表单中执行的唯一操作。
html 表单看起来像这样
<form id="photo1">
<input id="1" name="pictureid" hidden />
<select name="phototype">
<option value="G">G Rated</option>
<option value="X">X Rated</option>
</select>
</form>
what I want to do, this I have a drop down box that lets my admin users rate pictures G rated and X rated. once they have selected this option I would like the form to be submitted.
I thought it would be as easy as sending the form ID, but seems not.
this is the only thing the user needs to do in the form.
the html form looks like this
<form id="photo1">
<input id="1" name="pictureid" hidden />
<select name="phototype">
<option value="G">G Rated</option>
<option value="X">X Rated</option>
</select>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想在 onchange 事件触发时提交表单,请使用以下代码:
If you want to submit the form when the onchange event is fired, this is the code:
这应该足够了,
它会自动找到相对形式,因此它也可以应用于多种形式。
或者,如果由于动态加载表单而希望使用
.live()
实现此目的,则使用This should be enough
It finds the relative form automatically, so it can apply to multiple forms as well.
Or if you want this with
.live()
due to loading forms dynamically, then use当前代码的问题是您的用户无法选择“G 级”,因为它是默认选择的。您应该添加一个空白选项。您可能还需要隐藏元素的值:
然后您可以使用以下 jQuery:
jsFiddle
The problem with your code currently is that your user can't select "G-rated", because it's selected by default. You should add a blank option. You probably also need a value for your hidden element:
You could then use the following jQuery:
jsFiddle
工作演示
working demo