jQuery Change() 是否适用于隐藏的表单元素
我在弹出窗口中有一张地图。我想将值(坐标)从该窗口传递回我的主窗口,并在坐标更改后触发一个方法。
在我的主窗口中,我有这个事件处理程序
$(".spatial").change
( function ()
{
alert('Handler for .change() called.');
}
);
由于某种原因,当此表单发生更改(value
属性发生更改)时,没有调用alert()。
<form action="#" id="spatial_points" class="spatial">
<input type="hidden" id="start_point" class="spatial" value=""/>
<input type="hidden" id="end_point" class="spatial" value=""/>
</form>
我知道change()仅适用于表单字段。我想知道这是否扩展到隐藏
表单字段?
选择地图后,上述代码如下所示:
<form id="spatial_points" class="spatial" action="#">
<input id="start_point" class="spatial" type="hidden" value="(-7.9091601975133266, 127.0170435)">
<input id="end_point" class="spatial" type="hidden" value="(-44.73273833806611, 154.790481)">
</form>
I have a map in a popup window. I want to pass values (coordinates) from that back to my main window and have a method triggered once the coordinates are changed.
In my main window I have this event handler
$(".spatial").change
( function ()
{
alert('Handler for .change() called.');
}
);
For some reason the alert() is not being called, when this form is getting changed (the value
attribute gets changed).
<form action="#" id="spatial_points" class="spatial">
<input type="hidden" id="start_point" class="spatial" value=""/>
<input type="hidden" id="end_point" class="spatial" value=""/>
</form>
I know that change() only works on form fields. I am wondering whether this extends to the hidden
form field?
This is what the above code looks like once a map selection has been made:
<form id="spatial_points" class="spatial" action="#">
<input id="start_point" class="spatial" type="hidden" value="(-7.9091601975133266, 127.0170435)">
<input id="end_point" class="spatial" type="hidden" value="(-44.73273833806611, 154.790481)">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 JavaScript 更改值时不会触发
change
事件。由于这是更改隐藏字段的唯一方法,因此不会生成此类事件。但是,您可以在更改值后手动触发事件处理程序:
The
change
event is not triggered when changing the value via JavaScript. And as this is the only way to change a hidden field, such an event won't be generated.You can, however, trigger the event handler manually once you changed the value: