gpt4 book ai didi

javascript - jQuery 加载 Div 损坏

转载 作者:行者123 更新时间:2023-12-02 17:11:48 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery Mobile 创建一个包含 3 个按钮的 HTML 订单类型页面:

  • 拿起
  • 下车
  • 发货

我已经创建了按钮并将它们正确地放置在页面上。现在,我想根据用户单击的按钮显示一个独特的表单。

看一下示例,我的选择是 jQuery、AJAX 或 Javascript。我已经在使用 jQuery,所以我尝试走这条路,但没有成功。添加了加载 HTML 和 JS 警报...我的页面将完全忽略 HTML 的加载,但仍然显示警报。我已经验证我的 div 命名正确,并且每个链接都有正确的 ID 集。所以我暂时放弃了 jQuery。

关于 javascript...在标签之间添加我的逻辑,然后再次...它会忽略 HTML 内容的加载。我尝试过将内容放入 div 中,重命名 div,将表单代码移动到单独的 .html 和 .txt,但仍然没有成功。我找到了一个工作示例 here并尝试将其代码强行放入我的页面中。同样,当包含在我的页面中时,它不会在单击按钮时加载任何内容。 (我使用的是 Chrome 版本 35.0.1916.153)

目前,我的页面代码如下:

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<title>Order Type</title>

<script type="text/javascript">
function showDiv(idInfo) {
var sel = document.getElementById('divLinks').getElementsByTagName('div');
for (var i=0; i<sel.length; i++) {
sel[i].style.display = 'none';
}
document.getElementById('result'+idInfo).style.display = 'block';
}
</script>

<link rel="stylesheet" href="assets/css/pp_mis_oa.css" />


<!-- Standard jQquery Mobile themes can be created and replaced, to apply universal styling -->
<!-- Go to: http://jquerymobile.com/themeroller/index.php to build one, and download it to the themes directory. -->
<link rel="stylesheet" href="themes/jqm-test/theme.min.css" />

<!-- Do not edit or remove the following jQuery framework files. -->
<link rel="stylesheet" href="lib/jquery.mobile.structure-1.3.1.min.css" />
<script src="lib/jquery-1.9.1.min.js"></script>
<script src="lib/jquery.mobile-1.3.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.4.min.js" type="text/javascript"></script>
</head>

<body>

<!-- Start Main Landing Page -->
<div data-role="page" data-theme="b" class="has_footer">

<div data-role="content">
<p>
<div id="buttonDiv" data-role="navbar">
<ul>
<li><a href="#" class="ui-btn-active ui-state-persist" id="eat_in" onclick="showDiv('1');return false">Pick Up</a></li>
<li><a href="#" id="take_out" onclick="showDiv('2');return false">Drop Off</a></li>
<li><a href="#" id="delivery" onclick="showDiv('3');return false">Ship It</a></li>
</ul>
</div><!-- /navbar -->
<div id="result" style="clear:both;"></div>

</div> <!-- End Content Div -->

<!-- start footer -->
<div data-role="footer" data-position="fixed" data-id="footer-nav" data-theme="d" class="footer-bar">
<div class="ui-grid-solo">
<div class="ui-block-a"><button type="v" data-theme="b">Continue</button></div>
</div>
</div><!-- end footer -->

</div>
<!-- End Main Landing Page -->

<div id="divLinks">
<div id="container1">Container #1<p>Whole bunch of text 1</div>
<div id="container2">Container #2<p>Whole bunch of text 2</div>
<div id="container3">Container #3<p>Whole bunch of text 3</div>
</div>

</body>

jQuery/Javascript 拒绝将我的内容加载到我的 div 中,这是怎么回事?有人可以帮我指出正确的方向吗?

谢谢!

最佳答案

如果您想使用 jQuery 执行此操作,您可以将 showDiv 函数更改为以下内容:

function showDiv(idInfo) {
//hide all divs
$('#divLinks div').each(function() { $(this).hide(); });
//show the one selected
$('#container'+idInfo).show();
}

要将内容从“容器”div 移动到“结果”div:

function showDiv(idInfo) {
//populate "result" div with selected content
$('#result').html($('#container'+idInfo).html());
}

关于javascript - jQuery 加载 Div 损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24762893/

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