gpt4 book ai didi

javascript - 如何使用 Jquery 动态弹出数据

转载 作者:行者123 更新时间:2023-11-28 17:03:10 25 4
gpt4 key购买 nike

这是我的情况,我试图在用户单击按钮时获取弹出/模态表单。我正在从 Link 获取表单数据但我不知道如何处理它。基本上我可以使用 bootstrap 创建一个模式,但问题是我无法将这个 Jquery 与 bootstrap 模式集成。那么如何解决这个问题。帮助我,我被困住了。

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
</head>

<body>

<div class="container">
<button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue1" id="btnAction1">Button API Call 1</button>
<button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue2" id="btnAction2">Button API Call 2</button>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</div>

<h1>Getting started with JSON Form</h1>
<form></form>
<div id="res" class="alert"></div>


<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em"
crossorigin="anonymous"></script>
<!-- <script type="text/javascript" src="deps/jquery.min.js"></script> -->
<script type="text/javascript" src="deps/underscore.js"></script>
<script type="text/javascript" src="deps/opt/jsv.js"></script>
<script type="text/javascript" src="lib/jsonform.js"></script>

<script type="text/javascript" >
$(document).ready(function () {

var test = function x() {
$('form').jsonForm({
schema: {
name: {
type: 'string',
title: 'Name',
required: true
},
age: {
type: 'number',
title: 'Age'
}
},
onSubmit: function (errors, values) {
if (errors) {
$('#res').html('<p>I beg your pardon?</p>');
} else {
$('#res').html('<p>Hello ' + values.name + '.' +
(values.age ? '<br/>You are ' + values.age + '.' : '') +
'</p>');
}
}
});
}

$('.btn-action').click(function () {
// update modal content
$('.modal-body').html(test())
// // show modal
$('#myModal').modal('show');
});
});

</script>

</body>

</html>

最后,我想要的是当我单击按钮时,模式应使用上面的表单数据打开。我不知道天气我是否正在接近它,请随意向我建议任何其他解决方案,我是初学者,这是我的工作。

最佳答案

$ is not defined表示没有找到jquery库,检查依赖,JSON Form库依赖jQuery,尝试添加jQuery库

关于javascript - 如何使用 Jquery 动态弹出数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51550638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com