我在.hide('slide')
许多元素上使用jQuery UI的动画.问题是当我margin
在这些元素上指定一个时,动画似乎跳了下来,一旦完成,就会返回到原来的位置.如果我margin
从这些元素中删除,问题就不复存在了.
div.score {
width: 32px;
height: 32px;
background-color: blue;
color: white;
text-align: center;
margin: 10px;
padding-top: 6px;
}
Run Code Online (Sandbox Code Playgroud)
$('div.score').click(function() {
var $this = $(this);
$this.hide('slide', { direction: 'right' }, 250, function() {
$this.show('slide', { direction: 'left' }, 250)
.text(parseInt($this.text(), 10) + 1);
});
});
Run Code Online (Sandbox Code Playgroud)
<div class="score">0</div>
<div class="score">0</div>
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释这是什么原因,这是一个错误吗?
我有一个属性<select>
元素multiple="multiple"
.在Chrome(v27)中,change()
当用户通过单击并使用鼠标拖动滚动时,会触发事件.选择值后,问题就不复存在了.
<select multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Run Code Online (Sandbox Code Playgroud)
$('select').on('change', function() {
alert('Changed!');
});
Run Code Online (Sandbox Code Playgroud)
这是Chrome的错误吗?我试过搜索但没有碰到任何东西.
我对使用children()
和find()
使用时的行为有点困惑:first
.
考虑以下标记:
<div class="parent">
<div>1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
<div class="parent">
<div>1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
Run Code Online (Sandbox Code Playgroud)
据我了解,下面应该返回元素的同一个集合,因为没有孙子(这是唯一的区别之间声明find()
和children()
中文档).
但是,如果我在第一个类中添加一个类.child
,结果会有所不同:
$('.parent').find('.child:first').addClass('active');
Run Code Online (Sandbox Code Playgroud)
结果如下:
<div class="parent">
<div>1</div>
<div class="child active">2</div>
<div class="child">3</div>
</div>
<div class="parent">
<div>1</div>
<div class="child active">2</div>
<div class="child">3</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当使用该children()
方法做同样的事情时,我得到:
<div class="parent">
<div>1</div>
<div class="child active">2</div>
<div class="child">3</div>
</div>
<div class="parent">
<div>1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
Run Code Online (Sandbox Code Playgroud)
为什么?
inputs
我的页面上有多个,所有这些都datepicker
附加了jQuery UI的小部件.
我想这样做是show/hide
在.ui-datepicker-calendar
根据data-calendar
上属性input
的元素.
例如:
<input type="text" data-calendar="false" />
<input type="text" data-calendar="false" />
<input type="text" data-calendar="true" />
Run Code Online (Sandbox Code Playgroud)
所以,前两个不应该显示.ui-datepicker-calendar
,但最后应该显示.
我以为我可以利用beforeShow
事件来设置元素的显示,但是,在事件触发时,.ui-datepicker-calendar
它还不存在:
$('input').datepicker({
beforeShow: function(el, dp) {
$('.ui-datepicker-calendar').toggle( !$(el).is('[data-calendar="false"]') );
}
});
Run Code Online (Sandbox Code Playgroud)
我看过类似的问题,答案是用CSS来隐藏.ui-datepicker-calendar
元素:
.ui-datepicker-calendar {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
但是,这对我不起作用,因为我需要根据元素的data-calendar
属性设置display 属性.
有没有一种简单的方法来实现这一目标?我查看了datepicker
API,但没有遇到任何问题.
data-calendar
是假的是否可以通过以下方式进行宽松:
('#sideBar').hide('slide', {direction: 'right' },
800, function(){...});
Run Code Online (Sandbox Code Playgroud)
目前它非常紧张,因为它可能会移动100到500像素(取决于内容).我一直在寻找谷歌和大多数人说使用缓和,但在查看文档时我看不到一个缓和的属性.
我有以下示例表代码,
<table id="Table1">
<thead>
<th>Title</th>
</thead>
<tbody>
<tr>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
<tr class='disabled'>
<td>Row 4</td>
</tr>
<tr>
<td>Row 5</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我在jQuery Sortable下面申请,工作正常,
$("#Table1 tbody").sortable({
});
Run Code Online (Sandbox Code Playgroud)
但是,现在我想排除类别为"禁用"的"tr"排序,我要应用下面的代码(jquery选择器),但它不起作用.选择器有什么问题吗?我必须在HTML表格中使用"thead"和"tbody".
或者有其他方法吗?谢谢,
$("#Table1 tbody tr:not(.disabled)").sortable({
});
Run Code Online (Sandbox Code Playgroud) 如果这是一个非常基本的问题,请道歉.我无意中发现它asort()
似乎适用于多维数组:
PHP示例
$animals = array(
1 => array('name' => 'Zebra'),
2 => array('name' => 'Fox'),
3 => array('name' => 'Rabbit'),
4 => array('name' => 'Dog'),
5 => array('name' => 'Cat')
);
asort($animals);
var_dump($animals);
Run Code Online (Sandbox Code Playgroud)
产量
array
5 =>
array
'name' => string 'Cat' (length=3)
4 =>
array
'name' => string 'Dog' (length=3)
2 =>
array
'name' => string 'Fox' (length=3)
3 =>
array
'name' => string 'Rabbit' (length=6)
1 =>
array
'name' => string 'Zebra' (length=5)
Run Code Online (Sandbox Code Playgroud)
我想知道为什么这有效吗?
我认为asort() …
我正在更新一些为eBay列表生成XML的代码,其中一部分是添加MPN.
对于单个列表,一切都运行正常,因为品牌和MPN可以通过ItemSpecifics
容器指定.但是,对于多变量列表,必须为每个变体指定MPN.
根据文档,它应该在变体的VariationSpecifics.NameValueList
容器中指定.
我添加了代码来执行此操作,从而生成XML:
<Variation>
<SKU>CODE</SKU>
<StartPrice>99.99</StartPrice>
<Quantity>124</Quantity>
<VariationSpecifics>
<NameValueList>
<Name>MPN</Name>
<Value>000001</Value>
</NameValueList>
<NameValueList>
<Name>Choose Colour</Name>
<Value>Black</Value>
</NameValueList>
</VariationSpecifics>
</Variation>
Run Code Online (Sandbox Code Playgroud)
发送列出产品的请求时,它会失败,并回复以下错误:
[1] => Array
(
[ShortMessage] => Variation Specifics Mismatch.
[LongMessage] => Variation Specifics provided does not match with the variation specifics of the variations on the item.
[ErrorCode] => 21916664
[SeverityCode] => Error
[ErrorClassification] => RequestError
)
[2] => Array
(
[ShortMessage] => Missing name in name-value list.
[LongMessage] => Missing name in …
Run Code Online (Sandbox Code Playgroud) min()的文档显示了以下示例:
// Multiple arrays of the same length are compared from left to right
// so in our example: 2 == 2, but 4 < 5
$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)
Run Code Online (Sandbox Code Playgroud)
给出以下代码:
$input = [
[3, 6],
[2, 9],
];
var_dump(min(...$input)); // returns [2, 9] as expected
Run Code Online (Sandbox Code Playgroud)
如果你使相同的数组关联,它会失败并且似乎总是返回第一个数组:
$input = [
["three" => 3, "six" => 6],
["two" => 2, "nine" => 9],
];
var_dump(min(...$input)); // returns ["three" => 3, "six" => …
Run Code Online (Sandbox Code Playgroud) 假设我有下orders
表,并且我正在检索所有failed
订单。
+----+------------------+-------+--------+
| id | email | total | status |
+----+------------------+-------+--------+
| 1 | john@example.com | 39.99 | failed |
|----|------------------|-------|--------+
| 2 | john@example.com | 39.99 | failed |
|----|------------------|-------|--------+
| 3 | pete@example.com | 19.99 | failed |
+----+------------------+-------+--------+
Run Code Online (Sandbox Code Playgroud)
我需要获取失败订单的总数以及它们的总和,但每个重复行仅获取一次(当相同email
且相total
同时,该行被视为重复)
目前我有一个非常简单的查询,它获取所有failed
订单的总数。我不知道如何去修改它返回所需的数据(我已经试过搞乱与周围DISTINCT
并GROUP BY
没有用。)
SELECT COUNT(*) AS `count`, SUM(`total`) AS `grand_total` FROM `orders` WHERE `status` = 'failed';
Run Code Online (Sandbox Code Playgroud)
返回:
+-------+-------------+
| count | grand_total |
+-------+-------------+ …
Run Code Online (Sandbox Code Playgroud) 我试图阻止某些键输入到输入框中,但只有在按住键的同时shift按下该键才会:
$('selector').keydown(function(e) {
console.log(e.shiftKey);
if (e.shiftKey && e.which == 51) {
e.preventDefault();
alert('Disallowed');
}
});
Run Code Online (Sandbox Code Playgroud)
警报触发,但角色仍显示在文本框中.
我试图寻找解释为什么会发生这种情况,但无济于事,任何帮助都将不胜感激!
编辑
删除alert
似乎解决问题(这似乎很奇怪),我真的很想知道为什么它以这种方式行事,它似乎没有任何意义.
谢谢
我很难理解为什么jQuery对象不能多次追加:
var $divObj = $('<div/>', { 'text': 'This is a div!' });
$('button').on('click', function() {
$('#example').append($divObj);
});
Run Code Online (Sandbox Code Playgroud)
<div id="example"></div>
<button>Add Div</button>
Run Code Online (Sandbox Code Playgroud)
这仅在第一次button
单击时有效.后续点击似乎没有做任何事情.
我知道我可以clone()
在追加对象时使用,或者可以将其div
作为字符串传递,但我正在寻找解释为什么追加对象不会多次工作的原因.
鉴于以下代码段:
setInterval( function() {
$( 'div' ).toggleClass( 'hide show' );
}, 2000 );
Run Code Online (Sandbox Code Playgroud)
div {
background-color: green;
height: 100px;
transition: opacity 2s;
width: 100px;
}
.hide {
opacity: 0;
visibility: hidden;
}
.show {
opacity: 1;
visibility: visible;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hide"></div>
Run Code Online (Sandbox Code Playgroud)
我不希望看到过渡,opacity
因为visibility
没有过渡,我认为会立即生效。但是,当.show
应用于 my 时div
,我看到了转换。当.hide
应用时,它(如我期望的)立即消失。
为什么?