我在我的网站上有一个html表单。我打电话给里面有三个值的jQueryUI对话框。当我在对话框中选择其中一个值时,它将返回到html表单,但是html正在重新加载,并且所有其他字段都被清除。如何将数据从jQueryUI对话框传递回html表单?
如何从对话框传递数据而不重新加载页面并丢失数据?
我在我的网站上有一个html表单。我打电话给里面有三个值的jQueryUI对话框。当我在对话框中选择其中一个值时,它将返回到html表单,但是html正在重新加载,并且所有其他字段都被清除。如何将数据从jQueryUI对话框传递回html表单?
如何从对话框传递数据而不重新加载页面并丢失数据?
您可以引用表单中的元素(例如,如果您想更新其值),在按钮的回调函数中添加一个选择器。
下面的示例演示如何在用户单击jQuery UI对话框中的按钮时更改ID为result
的DIV的内容。
直播下面的例子:
http://jsfiddle.net/gibbok/m7gzt32o/
$("#dialog-message").dialog({
modal: true,
draggable: false,
resizable: false,
position: ['center', 'top'],
show: 'blind',
hide: 'blind',
width: 400,
dialogClass: 'ui-dialog-osx',
buttons: {
"I've read and understand this": function() {
// this code s executed when user click the button inside the dialog
$(this).dialog("close");
$('#result').text('some info here');
}
}
});
body {
font: normal normal normal 10px/1.5 Arial, Helvetica, sans-serif;
}
.ui-dialog-osx {
-moz-border-radius: 0 0 8px 8px;
-webkit-border-radius: 0 0 8px 8px;
border-radius: 0 0 8px 8px;
border-width: 0 8px 8px 8px;
}
<p>Hello World!
</p>
<form>
<div id="result"></div>
<div id="dialog-message" title="Important information">
<span class="ui-state-default"><span class="ui-icon ui-icon-info" style="float:left; margin:0 7px 0 0;"></span></span>
<div style="margin-left: 23px;">
<p>
We're closed during the winter holiday from 21st of December, 2010 until 10th of January 2011.
<br />
<br /> Our hotel will reopen at 11th of January 2011.
<br />
<br /> Another line which demonstrates the auto height adjustment of the dialog component.
</p>
</div>
</div>
</form>
这就是: ) 谢谢你的帮助。 –
@MichalT太棒了!我很高兴我的回答帮助你解决了你的问题。请不要忘记使用答案左侧的“嘀嗒”图标来接受/提升它。感谢您的协作和快乐编码:) – GibboK
请发表你做了什么已经你的代码? – prasanth
有''return false'或jquery'event.preventDefault()'的形式阻止使用这里有一些参考文献http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_preventdefault – prasanth