我正在开发我的第一个jQuery Mobile项目并遇到了障碍.我使用的是1.0版,到目前为止,该项目非常简单,只有索引上有三个脚本.我$(document).ready(function() { ... });最初使用不正确,然后在文档中读到正确的事情是绑定pageinit或pagecreate.这是我正在进行测试的脚本(直接从文档中):
$("#main").live('pageinit', function(event) {
alert( 'This page was just enhanced by jQuery Mobile!' );
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这个作为外部JS文件和#mainDIV中的脚本,正如我在这里找到的一些旧线程中所建议的那样.这在第一次加载索引时有效,但是当用户导航到另一个页面然后返回(重新访问)时,它不会再次触发.
我错过了什么?
如果我在我的jQuery Mobile应用程序中有一个链接,并使其成为一个按钮.button();.如果我单击文本(按钮的中心),它将不会引发事件"单击".
这是一个例子:http: //jsfiddle.net/9rZHg/
运行此脚本,并尝试瞄准文本.警报弹出窗口不会显示.只有当您单击按钮的其他部分时,它才会起作用.
在设备上进行测试时会发生同样的情况.
有没有一种简单的方法来避免这种情况,或者我是否必须<button>在我的应用程序中使用标签?
谢谢
我遇到了FancyBox的问题.我升级到V2,现在我的FancyBoxes似乎是200px.我曾经能够拥有只50 - 60 px高一点的FB,因为只有一行文字.发生了什么?
我已尝试(单独,但不是同时)将以下内容添加到FB的设置中:
autoSize: true
height: 60
height: '60px'
autoDimensions: true
Run Code Online (Sandbox Code Playgroud)
想法?
jQuery有一个所谓的新方法on()被建议更换delegate(),live()和.bind().
例如,使用两种方法:
$('#some-button').on('click', function() {
//do something when #some-button is clicked
});
$('#some-button').live('click', function() {
//do something when #some-button is clicked
});
Run Code Online (Sandbox Code Playgroud)
哪一个表现更好?(我知道这两个事件上下文都在文档级别.)
我正在使用jQuery 1.7.1从这个表中删除元素tr,它在Internet Explorer中运行不正常(我有8.07,但我想更多的IE会这样做 - 其他人也有同样的事情)
删除电话:
$("#tr_video_element_1").remove();
Run Code Online (Sandbox Code Playgroud)
当我这样做时,屏幕变黑(看起来像是一个youtube iframe背景或者其他东西 - 几天前网站的一部分是其中一个YouTube视频的链接).
代码验证正常.我究竟做错了什么?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" href="css/smoothness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="js/sorted_elements.js" type="text/javascript"></script>
<script src="js/ajax.js" type="text/javascript"></script>
<title> Panel </title>
</head>
<body><table id="editorial_table"><thead><tr>
<th>Position</th>
<th>Youtube video id</th>
<th>Video</th>
<th>Delete</th>
</tr>
</thead><tbody><tr class="video_tr_element" id="tr_video_element_1"><td><input readonly="readonly" class="position" name="input_position_1" id="input_position_1" size="1" type="text" value="1" /></td><td><input class="yt_link" name="yt_link_position_1" id="yt_link_position_1" type="text" …Run Code Online (Sandbox Code Playgroud) 我有一个id为"main"的div,我想使用jQuery设置它的高度并使其在window.resize高度上使用函数进行修改但是由于某种原因它只在增加窗口的高度时才有效,当减少它时它不会工作.
这是JS:
function setMainH() {
var docH = $(document).height();
$("#main").height(docH - 40);
}
$(function() {
setMainH();
});
$(window).resize(function() {
setMainH();
});
Run Code Online (Sandbox Code Playgroud)
编辑:问题出现增加或减少
编辑2:resize()事件似乎被正确调用,我试过
console.log("resizing");
Run Code Online (Sandbox Code Playgroud)
调整大小,它正确记录,所以问题不是这样.
我一直在努力寻找一种方法来更改标题中的按钮而不会丢失格式.我想将带有删除图标的删除按钮更改为带有复选图标的完成按钮.
这是代码的缩短版本:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
<script type="text/javascript">
function swapButton() {
$('#button').attr('data-icon', 'check').text('Done').trigger('create');
$('#header').trigger('create');
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-position="fixed" id="header">
<a data-icon="delete" id="button" onclick="swapButton()">Delete</a>
<h1>Test Page</h1>
</div>
<div data-role="content">
<p>Click on Delete to get Done button</p>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这会正确更改按钮的文本,但所有格式都会消失.
我已经尝试使用trigger('create')按钮和标题不起作用,我也尝试过.page()我在其他地方读到的方法,我也试过了.button().
我想不出别的想法.
我已经用了很多插件,如curvycorners,DD_roundies,behavior: url(ie-css3.htc);,但它不能很好地工作,所以没有人知道任何其他招数我都可以成为圆角的IE浏览器?我的网站是可调整大小的(口香糖),元素的颜色正在动态变化,所以我无法绘制图像.
我有一个简单的淡入淡出,我想无限期地进出.我发现插件可以做到这一点但是好奇如果jquery已经有了一个loop()api所以我可以在脚本中处理它.
<script type="text/javascript">
$(document).ready(function(){
$('.bottom-left').delay(1000).fadeIn(900);
$('.bottom-right').delay(3000).fadeIn(700);
});
</script>
Run Code Online (Sandbox Code Playgroud) 试图更好地理解Jquery的On()和off().不明白为什么这不起作用.我想激活和停用id TurnON和TurnOff Js.
使用Javascript
$(document).ready(function(){
$(document).on("click.turnon","#TurnOn",function() {
$(document).off('click.turnon');
alert("Turn Off is now turned off");
});
$(document).on("click.turnoff","#TurnOff",function() {
$(document).on('click.turnon');
alert("Turn Off is now turned back on");
});
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div id="TurnOn">Turn Off</div>
<div id="TurnOff">Turn On</div>
Run Code Online (Sandbox Code Playgroud)