可能重复:
jQuery美元符号未定义
我想知道为什么会TypeError: $ is undefined出现Error,我知道替代方法是使用jQuery解决问题,为什么$是未定义的,即使在使用正确的jQuery插件之后也是如此.
任何人都可以给我关于这个的解释,我知道可以使用的替代方案以及为什么该替代方案有效.任何人都可以解释一下.
也许我现在太累了,但我找不到插件开发人员使用以下结构的原因:
jQuery.<myPlugin> || (function($)) {
var $.<myPlugin> = {
// plugin code goes here...
}
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
当然这是一个常见的结构,除了使用||(据我所知的OR运算符),我不明白.
你能告诉我为什么开发人员使用了||吗?
在jsp页面中,我使用struts2-jquery-plugin-3.2.1.jar(它使用内部jquery-1.6.4.js),我使用的是facebox(它使用jquery-1.4.3.min.js).所以我的struts2-jquery-plugin-3.2.1.jar首先加载facebox jquery.但当我把jquery-1.4.3.min.js我的struts2-jquery-plugin-3.2.1.jar停止工作时,当我删除jquery-1.4.3.min.js时,我的facebox显然停止工作.我按照这些论坛:这里和这里但不能解决这个问题.一个人建议我使用新版本的struts2-jquery-plugin,但我不能使用因为如果我使用新版本的struts2-jquery-plugin那么我的项目的一些代码停止工作.请分享您对此问题的了解.
我的JSP页面中有以下内容,我收到错误
Message: Object doesn't support this property or method
Run Code Online (Sandbox Code Playgroud)
在 $("#projects").dataTable({
如果我删除
.makeEditable({
sAddURL: "addController"
});
Run Code Online (Sandbox Code Playgroud)
那么没有js错误,我该如何解决这个问题呢?
JS代码
$(document).ready(function () {
$("#projects").dataTable({ // error here
"bServerSide": true,
"sAjaxSource": "mycontroller",
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": true
}).makeEditable({
sAddURL: "addController"
});
});
Run Code Online (Sandbox Code Playgroud)
我有以下js文件
<script src="scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="scripts/jquery.dataTables.editable.js" type="text/javascript">
</script>
<script src="scripts/jquery.jeditable.js" type="text/javascript"></script>
<script src="scripts/jquery.validate.js" type="text/javascript"></script>
<script src="scripts/jquery-ui.js" type="text/javascript"></script>
<script src="scripts/jquery.js" type="text/javascript"></script>
<script src="scripts/jquery.dataTables.min.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud) 嗨,我想在我的应用程序中实现天气功能.所以对于这个我需要使用天气API.所以任何人都可以建议我使用哪个天气API,并教程如何使用jquery Mobile实现这一点.
我正在使用插件"DataTables",我想逐行添加图像,当用户点击时,调用另一个网址.
我按照www.datatables.net的例子,但是给出了以下错误:
DataTables warning(table id ='myDataTable'):从第0行的数据源请求未知参数'4'.
记录显示在屏幕上
<h2>Index</h2>
<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "AjaxHandler",
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "mDataProp": "ID", "bSortable": false },
{ "mDataProp": "Nome", "sTitle": "Identificação do produto" },
{ "mDataProp": "Address", "sTitle": "Descrição do produto" },
{ "mDataProp": "Town" },
{ "fnRender": function (o) {return '<a href=/Produto/Detalhar/' + o.aData[0] + '>' + 'More' + '</a>';}}
],
});
});
</script>
<table id="myDataTable" class="display">
<thead>
<tr>
<th>ID</th>
<th>Company name</th> …Run Code Online (Sandbox Code Playgroud) 我正在编写一个jQuery插件,需要跟踪页面中使用该插件的对象数量.有没有办法在插件中创建一个跟踪自身实例的静态变量?
这是我到目前为止插件的内容:
(function ($) {
$.fn.my_plugin = function (options)
{
var plugin_count = 0;
return this.each(function() {
alert(++plugin_count);
});
}
}(jQuery));
Run Code Online (Sandbox Code Playgroud)
在我的页面上:
<div class="plugin_div"></div>
<div class="plugin_div"></div>
<div class="plugin_div"></div>
<div class="plugin_div"></div>
<script language="javascript">
$('.plugin_div').my_plugin();
</script>
Run Code Online (Sandbox Code Playgroud)
当页面加载时,我收到四个警报,显示"1".
我怎么写这个,以便变量为每个调用的元素递增my_plugin()?
编辑:修复了糟糕的copypaste工作.
<div id="file">
<input type="file" name="txtImage[]" class="upload" />
<input type="text" name="txtImageDesc[]" class="desc" />
</div>
<input type="button" value="Add" name="addButton" id="addButton" />
<input type="button" value="Remove" name="removeButton" id="removeButton" />
Run Code Online (Sandbox Code Playgroud)
这是我的html div我需要在按钮点击时添加和删除这里是我的jquery代码
<script type='text/javascript'>
$('#addButton').click(function(){
$('.upload:last').clone().appendTo('#file');
$('.desc:last').clone().appendTo('#file');
});
$('#removeButton').click(function(){
$('.upload:last').clone().remove('#file');
$('.desc:last').clone().remove('#file');
});
</script>
Run Code Online (Sandbox Code Playgroud)
问题是"添加"按钮,它完美地工作但是在删除按钮上却没有.当我点击删除按钮时,我需要删除克隆的div.
如何在init函数中单击滑动事件?我是插件开发的新手,所以我需要一点帮助?
我正在编码:
(function( $ ) {
var methods = {
init: function(){
return this.bind('click',methods.slide());
},
slide: function() {
alert('I\'m sliding');
// and lets the element color turns into green
return this.css('color','green');
}
};
$.fn.myPlugin = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || !method ) {
return methods.init.apply( this, arguments );
} else {
$.error( ' Method ' + method + ' doesn\'t …Run Code Online (Sandbox Code Playgroud) 有时我需要将变量值替换为另一个
所以我使用这种方法
var $$test = "First",
$$test = "Second";
Run Code Online (Sandbox Code Playgroud)
代码工作正常,但我使用jsfiddle JSHint按钮检查JavaScript上的任何错误(它帮了我很多)
但是我得到了这个错误'$$ test'已经定义了
那么重新定义任何变量的理想方法是什么
谢谢 :)
jquery ×10
jquery-plugins ×10
javascript ×4
ajax ×1
cordova ×1
datatables ×1
html5 ×1
operators ×1