我有jQuery AJAX函数,它在查询数据库后返回HTML.根据查询结果,函数将根据需要返回HTML代码或不返回任何内容(即空白).
我需要有条件地检查数据何时为空.
$.ajax({
type:"POST",
url: "<?php echo admin_url('admin-ajax.php'); ?>",
data: associated_buildsorprojects_form,
success:function(data){
if(!data){
//if(data="undefined"){
//if(data==="undefined"){
//if(data==null){
//if(data.length == 0){
//if ( data.length != 0 ){
//if(data===0){
//if(data==="0"){
alert("Data: " + data);
}
},
error: function(errorThrown){
alert(errorThrown);
alert("There is an error with AJAX!");
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试了各种条件但没有正确检查数据.根据我的发现,空白警报消息并不意味着数据
如果不是这些东西,我怎么能有条件地检查产生空白警报消息的数据?
我有一个这样的无序列表:
<div class="list">
<ul>
<li>
list1
<ul>
<li>Sub list1</li>
<li>Sub list2</li>
<li>Sub list3</li>
</ul>
</li>
<li>
list2
<ul>
<li>Sub list1</li>
<li>Sub list2</li>
<li>Sub list3</li>
</ul>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我现在想要只为第一个列表应用CSS,而不是它的子ul和li.我尝试过以下方法:
.list ul li{
background:#ccc;
}
Run Code Online (Sandbox Code Playgroud)
...但背景颜色应用于所有列表.应该怎么做才能改变只有父级而不是子级的CSS.
我有一个选择元素.一些选项同时具有class(.filterable_option)和custom属性(data-clienturn).
基于另一个元素的on change事件,我需要从select元素中删除以下选项:
.filterable_option.var = $some_value)的值.HTML:
<select name="myselect_a">
<option selected="selected"></option>
<option value="Apply filter">Apply filter</option>
</select>
<select name="myselect_b">
<option selected="selected"></option>
<option data-customattribute="58" value="1" class="filterable_option">Dog</option>
<option data-customattribute="58" value="2" class="filterable_option">Cat</option>
<option data-customattribute="60" value="3" class="filterable_option">Parrot</option>
<option>I have no class or custom attribute.</option>
</select>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('#myselect_a').on('change', function() {
var $myselect_a_option = $("#myselect_a").val();
if($myselect_a_option === 'Apply filter'){
var $some_value = '58';
$("select[name=myselect_b] option.filterable_option[data-customattribute!=" + $some_value + "]").remove();
}
});
Run Code Online (Sandbox Code Playgroud)
的jsfiddle:
为了您的方便:http: …
上述功能可以组合成一个以产生更有效的代码吗?它看起来非常重复.
JSFiddle:http://jsfiddle.net/clarusdignus/843YW/1/
HTML:
<label>Industry:</label>
<select name="industry">
<option selected="selected"></option>
<option value="ag">Agriculture</option>
<option value="co">Corporate</option>
</select>
<input type="text" disabled="disabled" name="industryspecifier"/>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('select[name=industry]').on('change', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
$('select[name=industry]').on('mouseup', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
$('select[name=industry]').on('mousedown', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
$('select[name=industry]').on('mouseout', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
$('select[name=industry]').on('keydown', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
$('select[name=industry]').on('keyup', function() {
$('[name=industryspecifier]').val($(':selected',this).val());
});
Run Code Online (Sandbox Code Playgroud) 是)我有的:
标签内的复选框.
<label for="foo">
<input type="checkbox" id="foo" />bar
</label>
Run Code Online (Sandbox Code Playgroud)
我需要的:
使用jQuery,我需要在span元素中包含复选框后面的文本(即"bar").
<label for="foo">
<input type="checkbox" id="foo" /><span>bar</span>
</label>
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
$('label').wrapInner('<span></span>');
Run Code Online (Sandbox Code Playgroud)
这不会根据需要排除复选框.
使用jquery-ui创建对话框非常简单:
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
...但是仍然需要HTML中的div来实现这一点.在道场:
var dlg = new dijit.Dialog({
title:"dialog",
style: "width:30%;height:300px;"
});
dlg.show();
Run Code Online (Sandbox Code Playgroud)
如果没有html部分中指定的任何内容,只会做诀窍,jquery-ui可以这样做吗?(我必须在这里使用jquery-ui)谢谢,
大卫
内容:
我有一个清单。使用jQuery,我可以动态地...
问题:
使用第n个子选择器的CSS样式(来自样式表)将应用于每个第三个列表项。问题是当我动态隐藏/显示列表项时,CSS nth-child选择器似乎没有重新计算。
由于jQuery已经在计算第三个列表项,因此我不需要重新计算CSS的第n个子选择器,除非没有办法取消它或将其销毁。
代码:
标记:
<ul class="teamlist">
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
jQuery:
$('.teamlist li:visible').each(function (i) {
if (i % 3 == 0) $(this).addClass('teamlist_fourth_item');
});
$('.teamlist li:visible').each(function (i) {
if ((i+1) % 3 == 0) $(this).addClass('teamlist_third_item');
});
Run Code Online (Sandbox Code Playgroud)
不需要的CSS:
.teamlist li:nth-child(3n+3) {
margin-right: 0;
}
Run Code Online (Sandbox Code Playgroud)
问题:
如何销毁或强制重新计算CSS nth-child选择器?
三个时间输入,包括开始时间、结束时间以及两者之间的差值。
<input type="time" name="starttime" id="starttime">
<input type="time" name="endtime" id="endtime">
<input type="time" name="duration" id="duration" disabled>
Run Code Online (Sandbox Code Playgroud)
当开始或结束时间更改时,差异会显示在第三个输入中。
例如 23:15 - 20:00 = 03:15。
到目前为止,我只能给出正确的小时数,而不能给出分钟数。
<script>
jQuery(document).ready(function($) {
function calculateTime() {
// Get values.
var valuestart = $("#starttime").val();
var valuestop = $("#endtime").val();
// Create date format.
var timeStart = new Date("01/01/2007 " + valuestart);
var timeEnd = new Date("01/01/2007 " + valuestop);
// Subtract.
var difference = timeEnd - timeStart;
// Attempt 1: Only gets hours.
//var difference_as_hours = difference …Run Code Online (Sandbox Code Playgroud) 我有一个带有用户名和密码文本框字段的登录表单。字段被包裹在标签中。
我需要删除标签的文本,因为我想改为应用占位符值。
注意:我已设法定位中断,但无法定位标签的呈现文本。
label[for=user_login] > br,
label[for=user_pass] > br {
display: none;
}Run Code Online (Sandbox Code Playgroud)
<p>
<label for="user_login">Username
<br>
<input type="text" name="log" id="user_login" class="input" value="" size="20">
</label>
</p>
<p>
<label for="user_pass">Password
<br>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20">
</label>
</p>Run Code Online (Sandbox Code Playgroud)
我需要一个基于 CSS 的解决方案。编辑标记不是一种选择。
带有自定义计数器的有序列表:
ol {
/*list-style-type:decimal-leading-zero;*/
list-style: none;
padding-left: 0px;
counter-reset: item;
}
ol>li {
display: table;
counter-increment: item;
}
ol>li:before {
display: table-cell;
padding: 0 0.5em 0 0;
content: counter(item) ".";
font-weight: bold;
}Run Code Online (Sandbox Code Playgroud)
<ol>
<li>List item one.</li>
<li>List item two.</li>
<li>List item three.</li>
<li>List item four.</li>
<li>List item five.</li>
<li>List item six.</li>
<li>List item seven.</li>
<li>List item eight.</li>
<li>List item nine.</li>
<li>List item ten.</li>
</ol>Run Code Online (Sandbox Code Playgroud)
任何编号小于 10 的列表项前的前导零。
即 01、02、03、04、05、06、07、08、09、10。
如何通过 CSS 实现所需的前导零?
jquery ×6
html ×5
css ×4
javascript ×4
ajax ×1
css-counter ×1
date ×1
dialog ×1
forms ×1
html-lists ×1
jquery-ui ×1
label ×1
null ×1
word-wrap ×1