- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对我的 codeigniter 应用感到困惑。
我有一个 View /表单( View 1),它在提交时加载另一个 View ( View 2)。 View 1,在初始页面加载时未加载正确的 js 和 css。它改为从 View 1 加载 js 和 css。如果我随后在 View 2 上点击刷新,则会加载正确的 css 和 js。
为了证明我的观点我放置了一个测试js脚本
<script type='text/javascript'>
alert('test');
</script>
作为 View 1 和 View 2 上的第一位代码。在第一次加载 View 1 时,会显示警报,当我在 View 1 上单击提交并加载 View 2 时,不会显示警报。如果我根据需要刷新警报显示。
因此 js 和 css 在初始加载时无法正确加载,但在刷新时可以完美运行。
有什么想法吗?
View 1
<script type='text/javascript'>
alert('test');
</script>
<html>
<head>
<title>
Capture New Order
</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
</head>
<body>
<div data-role="page" data-theme="a">
<div class="wrap-header">
<div data-role="header" data-mini="true" data-ajax="false">
<a data-icon="grid" data-mini="true" data-theme="a" onclick="window.location.href='/pointer'">Menu</a>
<h3>New Order Details</h3>
</div>
</div>
<div data-role="content">
<form id="sales_order_details" action="/sales/new_blank_order_lines" method="post">
<label for="customer">Select Customer</label>
<div id="autocomplete_dropdown">
<input type="text" id="customer" name="customer" />
</div>
<label for="period">Desired Order Period</label>
<select id="period" name="period">
<option value="0"></option>
<?php
for($i = 0; $i <= 365; $i ++){
$startdate = strtotime("today + $i day");
$enddate = strtotime("today + " . ($i + 6) . " day");
if(date('D', $startdate) == 'Mon'){
echo '<option value="' . date('Y-m-d', $startdate) . '">' .date('d M y', $startdate) . " to " . date('d M y', $enddate) . "</option>";
}
}
?>
</select>
<label>Choose an order type below and provide requested details</label>
<div data-role="collapsible-set">
<div data-role="collapsible">
<h3>
Auto Spread Order
</h3>
<label for="asuom">Unit of Measure for Order</label>
<select id="asuom" name="asuom">
<option value="0"></option>
<option value="Bundles">Bundles</option>
<option value="Cubes">Cubes</option>
<option value="Pieces">Pieces</option>
</select>
<label>Number of Cubes to Autospread</label>
<input type="text" name="ascubes" id="ascubes">
<label>Products over which to spread</label>
must work on this...
<input type="submit" name="previous_order" id="previous_order" value="Continue">
</div>
<div data-role="collapsible">
<h3>
Previous Order
</h3>
<label>Select Order to use as template</label>
<input type="submit" name="previous_order" id="previous_order" value="Continue">
</div>
<div data-role="collapsible">
<h3>
Blank Order
</h3>
<label for="buom">Unit of Measure for Order</label>
<select id="buom" name="buom">
<option value="0"></option>
<option value="cubes">Bundles</option>
<option value="cubes">Cubes</option>
<option value="pcs">Pieces</option>
</select>
<input type="submit" name="blank_order" id="blank_order" value="Continue">
</div>
</div>
</form>
</div>
</body>
</html>
<!-- script for page start-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script type="text/javascript">
$(function(){
$("#customer").autocomplete({
source: "get_customers",
messages: {
noResults: '',
results: function() {}
}
});
});
</script>
View 2
<script type='text/javascript'>
alert('test');
</script>
<?php
$newperiod = date('Y-m-d',strtotime($period) + (24*3600*6));
?>
<html>
<head>
<title>
Capture blank Order
</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript">
function callAutocomplete(element)
{
$(element).autocomplete(
{
source: "get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('sales/get_sku_prices', {data:selectedObj.value},function(result) {
$(ui).parent('tr').find('input[id^="pricepercube"]').val(result);
});
}
});
}
$(function()
{
var counter = 1;
jQuery("table.authors-list").on('change','input[name^="qty"]',function(event)
{
event.preventDefault();
counter++;
var newRow = jQuery('<tr>'+
' <td><a class="deleteRow"> <img src="<?php echo base_url() ?>application/assets/images/no.jpg" /></a></td>' +
' <td><input type="text" id="product' + counter + '" name="product' + counter + '" /></td>' +
' <td><input type="text" id="qty' + counter + '" name="qty' + counter + '" /></td>'+
' <td><input type="text" id="price' + counter + '" name="price' + counter + '" /></td>'+
' <td><input type="text" id="discount' + counter + '" name="discount' + counter + '" /></td>'+
' <td valign=top><input type="checkbox" id="treated' + counter + '" name="treated' + counter + '" /></td>'+
' </tr>');
jQuery('table.authors-list').append(newRow);
callAutocomplete("#product"+ counter);
});
$("#product").autocomplete(
{
source: "get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('<?=site_url("sales/get_sku_price")?>', {data:value},function(result)
{
$("#price").val(result);
});
}
});
});
</script>
</head>
<body >
<div class="wrap-header">
<div data-role="header" data-mini="true" data-ajax="false">
<a data-icon="grid" data-mini="true" data-theme="a" onclick="window.location.href='/pointer'">Menu</a>
<h3>New Blank Order</h3>
</div>
</div>
<div data-role="content">
<center>
<table width=80%><tr><td>
<input type="text" name="customer" id="customer" value="<?php echo $customer; ?>" disabled>
</td><td>
<input type="text" name="period" id="period" value="<?php echo $period." to ".$newperiod; ?>" disabled>
</td><td>
<input type="text" name="buom" id="buom" value="<?php echo $buom; ?>" disabled>
</td></tr></table>
</center>
</div>
<table class="authors-list" border=0>
<tr><td></td><td>Product</td><td>Qty</td><td>Price/Cube</td><td>Discount</td><td>treated</td></tr>
<tr>
<td><a class="deleteRow"> <img src="<?php echo base_url() ?>application/assets/images/no.jpg" /></a></td>
<td><input type="text" id="product" name="product" /></td>
<td><input type="text" id="qty" name="qty" /></td>
<td><input type="text" id="price" name="price" /></td>
<td><input type="text" id="discount" name="discount" /></td>
<td valign="top" ><input type="checkbox" id="treated" name="treated" /></td>
</tr>
</table>
</body>
</html>
初始页面加载 - 没有警报或 js/css 工作 - 只有来自 View 1 的 css 和 js
刷新加载 - View 1 中没有 css 或 js,仅加载 View 2 css 和 js。请注意,我已经从 View 2 中删除了所有样式,只是为了测试和开始工作。所以下图是我想要的。此处显示警报。这是关闭警报后的加载。
我在 IE、Firefox 和 Chrome 中都试过了,结果都一样。
欢迎任何建议。谢谢
更新
View 1:
<html>
<head>
<title>
Capture New Order
</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<!-- script for page start-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script type="text/javascript">
$(document).on('pageshow', '#pagebody', function(){
$(function(){
$("#customer").autocomplete({
source: "get_customers",
messages: {
noResults: '',
results: function() {}
}
});
});
});
</script>
<!-- script for page end-->
</head>
<body>
<div data-role="page" data-theme="a">
<div class="wrap-header">
<div data-role="header" data-mini="true" data-ajax="false">
<a data-icon="grid" data-mini="true" data-theme="a" onclick="window.location.href='/pointer'">Menu</a>
<h3>New Order Details</h3>
</div>
</div>
<div data-role="content">
<form id="sales_order_details" action="/sales/new_blank_order_lines" method="post">
<label for="customer">Select Customer</label>
<div id="autocomplete_dropdown">
<input type="text" id="customer" name="customer" />
</div>
<label for="period">Desired Order Period</label>
<select id="period" name="period">
<option value="0"></option>
<?php
for($i = 0; $i <= 365; $i ++){
$startdate = strtotime("today + $i day");
$enddate = strtotime("today + " . ($i + 6) . " day");
if(date('D', $startdate) == 'Mon'){
echo '<option value="' . date('Y-m-d', $startdate) . '">' .date('d M y', $startdate) . " to " . date('d M y', $enddate) . "</option>";
}
}
?>
</select>
<label>Choose an order type below and provide requested details</label>
<div data-role="page" data-theme="a" id="pagebody">
<div data-role="collapsible-set">
<div data-role="collapsible">
<h3>
Auto Spread Order
</h3>
<label for="asuom">Unit of Measure for Order</label>
<select id="asuom" name="asuom">
<option value="0"></option>
<option value="Bundles">Bundles</option>
<option value="Cubes">Cubes</option>
<option value="Pieces">Pieces</option>
</select>
<label>Number of Cubes to Autospread</label>
<input type="text" name="ascubes" id="ascubes">
<label>Products over which to spread</label>
must work on this...
<input type="submit" name="previous_order" id="previous_order" value="Continue">
</div>
<div data-role="collapsible">
<h3>
Previous Order
</h3>
<label>Select Order to use as template</label>
<input type="submit" name="previous_order" id="previous_order" value="Continue">
</div>
<div data-role="collapsible">
<h3>
Blank Order
</h3>
<label for="buom">Unit of Measure for Order</label>
<select id="buom" name="buom">
<option value="0"></option>
<option value="cubes">Bundles</option>
<option value="cubes">Cubes</option>
<option value="pcs">Pieces</option>
</select>
<input type="submit" name="blank_order" id="blank_order" value="Continue">
</div>
</div>
</form>
</div>
</body>
</html>
View 2:
<?php
$newperiod = date('Y-m-d',strtotime($period) + (24*3600*6));
?>
<html>
<head>
<title>
Capture blank Order
</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).on('pageshow', '#pagebody', function(){
function callAutocomplete(element)
{
$(element).autocomplete(
{
source: "get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('get_sku_prices', {data:selectedObj.value},function(result)
{
$(element).parent().parent().find('input[id^="price"]').val(result);
});
}
});
}
$(function()
{
var counter = 1;
jQuery("table.authors-list").on('change','input[name^="qty"]',function(event)
{
event.preventDefault();
counter++;
var newRow = jQuery('<tr>'+
' <td><a class="deleteRow"> <img src="<?php echo base_url() ?>application/assets/images/no.jpg" /></a></td>' +
' <td><input type="text" id="product' + counter + '" name="product' + counter + '" /></td>' +
' <td><input type="text" id="price' + counter + '" name="price' + counter + '" /></td>'+
' <td><input type="text" id="qty' + counter + '" name="qty' + counter + '" class="linetotal" /></td>'+
' <td><input type="text" id="total' + counter + '" name="total' + counter + '" /></td>'+
' <td><input type="text" id="discount' + counter + '" name="discount' + counter + '" /></td>'+
' <td valign=top><input type="checkbox" id="treated' + counter + '" name="treated' + counter + '" /></td>'+
' </tr>');
jQuery('table.authors-list').append(newRow);
callAutocomplete("#product"+ counter);
});
$("#product").autocomplete(
{
source: "get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('get_sku_prices', {data:selectedObj.value},function(result) {
$("#product").parent().parent().find('input[id^="price"]').val(result[0]);
});
}
});
//code to calculate line cost (price*qty)
var total=Number($('input[id^="price"]').val()) + Number($('input[id^="qty"]').val());
$('input[id^="total"]').val(total);
//code to calculate Grand Total of all line costs (sum of all line totals)
});
});
</script>
</head>
<body >
<div data-role="page" data-theme="a" id="pagebody">
<div class="wrap-header">
<div data-role="header" data-mini="true" data-ajax="false">
<a data-icon="grid" data-mini="true" data-theme="a" onclick="window.location.href='/pointer'">Menu</a>
<h3>New Blank Order</h3>
</div>
</div>
<div data-role="content">
<center>
<table width=80%><tr><td>
<input type="text" name="customer" id="customer" value="<?php echo $customer; ?>" disabled>
</td><td>
<input type="text" name="period" id="period" value="<?php echo $period." to ".$newperiod; ?>" disabled>
</td><td>
<input type="text" name="buom" id="buom" value="<?php echo $buom; ?>" disabled>
</td></tr></table>
</center>
</div>
<table class="authors-list" border=0>
<tr><td></td><td>Product</td><td>Price/Cube</td><td>Qty</td><td>Line Total</td><td>Discount</td><td>treated</td></tr>
<tr>
<td><a class="deleteRow"> <img src="<?php echo base_url() ?>application/assets/images/no.jpg" /></a></td>
<td><input type="text" id="product" name="product" /></td>
<td><input type="text" id="price" name="price" /></td>
<td><input type="text" id="qty" name="qty" onchange="fill()" /></td>
<td><input type="text" id="total" name="total" class="linetotal" /></td>
<td><input type="text" id="discount" name="discount" /></td>
<td valign="top" ><input type="checkbox" id="treated" name="treated" /></td>
</tr>
</table>
</div>
</body>
最佳答案
首先,您的代码中存在一个大问题。使用 jQuery Mobile 时,初始化 javascript/jquery 代码的唯一正确方法是 jQuery Mobile 页面事件。如果您使用 document ready
或 $(function(){
来初始化您的代码,它很有可能会失败是因为:
为防止这种情况,强烈建议使用 jQuery Mobile 页面事件。这是一个有效的 jsFiddle
示例:http://jsfiddle.net/Gajotres/tuJEm/
$(document).on('pageshow', '#index', function(){
alert('Page loaded');
});
$(document).on('pagebeforeshow', '#second', function(){
alert('Page loaded');
});
为了使其适用于您的情况,您需要为您的页面容器提供一个 id:
<div data-role="page" data-theme="a">
如果您想更好地理解这一点,请查看此 ARTICLE ,或找到它 HERE .
还有一件事,由于 jQM 页面事件,您不再需要在 HTML 文件末尾加载脚本。无论如何,如果是 jQM,您的 jQm js 和 css 应该始终在您的 html header 中。
编辑:
在调查 jQuery Mobile + Codeigniter 问题后。我无法确认这是否有效,但您应该尝试一下。显然,codeigniter 在 jQuery Mobile 如何通过 AJAX 处理页面加载方面存在问题。所以基本建议是将其关闭。
您需要做的第一件事是将您所有的脚本和样式标签移到 HEAD 中。每个 PHP 文件都应该有相同的一组 jQuery、jQuery Mobile js 文件加载到头部。这样做是因为我们将阻止页面加载到 DOM 中,并且每个页面都将作为一个实体存在。
第二件事,ajax 页面加载:
<script>
$(document).bind("mobileinit", function() {
$.mobile.ajaxEnabled = false;
});
</script> <!-- Note your script before jqm -->
还有一点,mobilinit
事件必须在 jQuery 之后但在 jQuery Mobile 之前初始化,像这样:
<script src="jquery.js"></script>
<script>
$(document).bind("mobileinit", function() {
$.mobile.ajaxEnabled = false;
});
</script> <!-- Note your script before jqm -->
<script src="jquery-mobile.js"></script>
关于jquery - codeigniter、jQuery Mobile、jQuery UI - 脚本未在首次加载时加载,仅刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654140/
$.mobile.pageContainer 是指包含其他虚拟页面的元素。它设置为 .所以我认为它可以改变。实际上,某些 JQM 方法 (changePage) 允许您为页面指定非默认页面容器。 J
如何在移动设备上更改方向时触发事件。 调整大小 在 iPod Touch 上运行良好,但在使用 Opera mobile 作为浏览器的移动设备上运行良好。 有关如何在 Opera mobile 上触发
我想为我拥有的装有 Windows Mobile 2003 的设备开发一些应用程序,但我不想为此寻找 Visual Studio 2003 的副本。我想知道是否可以将 Mobile 6 SDK 用于此
我试图阻止 jQuery Mobile 在调用 changePage 时隐藏加载微调器。 程序流程是这样的,从点击一个链接开始,它的点击事件定义如下: $('body').delegate('.lib
我想为运行 Windows Mobile 5 的扫描仪开发应用程序。 MSDN 站点说要下载最新的 SDK(Windows Mobile 6 Professional SDK)。这会起作用还是我应该下
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在尝试使用 Jquery mobile 创建弹出菜单,通过单击按钮,它应该在不更改页面的情况下弹出菜单选项,类似于 jquery mobile 的选择菜单。在 JQM 中有没有办法做到这一点? 谢
在移动设备中,当我打开我的页面并选择一个输入框时,虚拟键盘打开,页面自动滚动以将输入框置于中心。 我不想要这个 Action 。 我搜索了很多答案,其中大多数建议在调整大小事件中手动调用以下 java
jQuery 移动列表中是否可以有多个拆分按钮? 我试过这样做: 1 但它不起作用。将链接包装在 中也不行.我做错了什么,
我想从我的 .js 文件中打开 .html 文件。所以我使用了 $.mobile.changePage("file.html")。在file.html 中有file.js。但是 file.js 在调用
我们有许多使用 Windows Mobile 6 的用户,需要应用较小的更改。例如。更新注册表设置。一种选择是使用我们的设备管理软件推送和执行可执行文件。 我希望这对熟悉 VBScript/JScri
我在PHP网站上有一个日期字段,并且我正在使用jQuery Mobile作为移动网站。 在移动浏览器(例如android上的firefox mobile)上浏览网站时,单击日期文本输入时,会出现日历对
我正在构建一个PhoneGap + JQuery Mobile应用程序,但似乎无法阻止它通过双击放大。我按照http://www.tricedesigns.com/2012/01/17/mobile-
随着 jQuery Mobile 1.3 的到来,.navigate()已添加功能。我听说这是更改页面的推荐方法,似乎他们解决了在页面之间传输数据的问题。 问题是,既然已经简化了,我该如何访问 cha
我想得到一个 input文本区域和 submit按钮附在它的右侧。 理想情况下,两者将使用 100% 的宽度并且并排放置。 我一直在尝试玩弄ui-grid-a和类似的选择,但一切都失败了。你可以看到一
我正在使用 jquery-mobile,我有这两个按钮: Pro: Reset 我希望它们并排显示(内联)。但我想不通。我做了this但它不起作用。你能帮我吗 ?这是我的 CSS:
我正在为 Windows Mobile 6.5 (Samsung Omnia II i8000) 开发 native 应用程序。进行一些更改后,我的应用程序在运行时挂起。 问题是我的应用程序也在启动期
有没有办法从周围和图标中删除背景光盘(圆圈)?我找到的光盘的唯一引用如下 background: rgba(0,0,0,.4) /*{global-ic
jQuery 移动版虽然在很多方面都很棒,但有时也令人沮丧。在这种情况下,我试图动态创建库中非常好的按钮之一。 基本上我想要做的是在输入字段中输入文本,当按下空格键时,它会创建一个带有文本的 jQue
我想在我的第 2 页上显示标题。使用以下内容是否有效: "> .... ? 最佳答案 这取决于你定义什么为“有效”
我是一名优秀的程序员,十分优秀!