如何在 javascript 中编写有条件加载 2 种不同 css 样式的代码 我需要在页面加载时和加载后加载不同的 css 样式。IE
if(condition)
{load 1 css};
else
{load another css};
Run Code Online (Sandbox Code Playgroud) 如果我在JavaScript中有一个数组,请说:
var a = [1, 2, 3];
var b = ["Praveen", "Kumar", "Stack", "Overflow"];
Run Code Online (Sandbox Code Playgroud)
如果我得到上述数组的长度:
a.length;
b.length;
Run Code Online (Sandbox Code Playgroud)
我得到了正确的值.即
a.length; // 3
b.length; // 4
Run Code Online (Sandbox Code Playgroud)
但是,如果我创建另一个数组,我将索引设置为:
c = [];
c[5] = "Five";
c[10] = "Ten";
Run Code Online (Sandbox Code Playgroud)
然后,如果我查询长度,它会告诉我11.
c.length // 11
Run Code Online (Sandbox Code Playgroud)
这是错的吗?或者这样JavaScript解释数组?请指导.
我有以下标记: -
<div class="fil hori now">
<span class="label-new">
<ul class="ngc">
<li>
<input class="any" id="any" name="any" type="checkbox">
<label id="any" for="any">Any</label>
</li>
<li class="new-select">
<input id="item1" name="item1" type="checkbox">
<label id="item1" for="item1">item1</label>
</li>
<li class="new-select">
<input id="item2" name="item2" type="checkbox">
<label id="item2" for="item2">item2</label>
</li>
<li class="new-select">
<input id="item3" name="item3" type="checkbox">
<label id="item3" for="item3">item3</label>
</li>
</ul>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我如何使项目列表水平,但如果我有新项目,他们只是以特定宽度而不是一行进入下一行?
我有一个使用HTMLand创建的表JSP。表的值是使用 JSP 动态创建的。我的代码类似于下图所示:
<link rel="stylesheet" type="text/css" href="css/table.css">
<HTML>
<BODY>
<div class="MyTable" >
<table border="0">
<thead>
<tr>
<td><b>User</b></td>
<td><b>Data</b></td>
</tr>
</thead>
<%
-----------------------
--- JAVA CODE ---------
-----------------------
if( condition ) //if condition satisfied, then a row of data is added
{
%>
<tr>
<td><%= GENERATED_FROM_CODE %></td>
<td><%= GENERATED_FROM_CODE %></td>
</tr>
<%
}
-----------------------
--- JAVA CODE ---------
-----------------------
%>
</BODY>
<HTML>
Run Code Online (Sandbox Code Playgroud)
有时数据很大,表变得很长。我想创建一个页面,其中只显示某个数字,比如一次显示10 行。应该有下图给出了一个链接下一/先前,第一/最后,页面 数量等,这将让你在表中的内容浏览。 …
我正在为图像添加一个类.
.bbbLink img {
outline: 1px solid #ddd;
border-top: 1px solid #fff;
padding: 10px;
background: #f0f0f0;
}
Run Code Online (Sandbox Code Playgroud)
在悬停时我添加了这个,
.bbbLink img:hover {
background-color: rgba(0, 0, 0, 0.1);
outline: 1px solid #ddd;
border-top: 1px solid #fff;
padding: 10px;
background: #f0f0f0;
}
Run Code Online (Sandbox Code Playgroud)
为了活跃,我这样做,
.bbbLink img:active {
outline: 1px solid #111 !important;
border-top: 1px solid #555 !important;
padding: 10px !important;
background: #333 !important;
}
Run Code Online (Sandbox Code Playgroud)
因为我将活动类添加到图像而你不能这样做,因为它是一个自我关闭元素我使用jquery来处理像这样添加活动状态,
<script>
(function($) {
$('.bbbLink').click(function() {
$(this).toggleClass('active');
});
})( jQuery );
</script>
Run Code Online (Sandbox Code Playgroud)
即使在单击我的活动类出现的元素后检查dom时,一切都很完美.
<a id="wrapbbb" class="bbbLink active" href="img.jpg" target="_blank">
<img …Run Code Online (Sandbox Code Playgroud) 我试图检查变量的值是否为空,但它不起作用。我还必须停止脚本并且不要插入行
网页
<input type="text" name="for_intitule" id="form_intitule">
Run Code Online (Sandbox Code Playgroud)
jQuery
var form_intitule = $('input[name=form_intitule]').val();
if(form_intitule == null){
alert('fill the blank');
return false;
}
Run Code Online (Sandbox Code Playgroud)
更新 :
$('#insertForm').on('click', function(){
var form_intitule = $('input[name=form_intitule]').val();
if($('input[name=form_intitule]').val().trim().length == 0){
alert('fill the blank');
}
$.ajax({
type: "GET",
url: "lib/function.php?insertForm="+insertForm+"&form_intitule="+form_intitule,
dataType : "html",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
success:function(data){
}
});
});
Run Code Online (Sandbox Code Playgroud) 这是我使用Datatables jQuery插件的代码,它通过AJAX将数据发送到服务器:
$('#allLessonAttachmentsTable').DataTable({
processing: true,
serverSide: true,
"bSort": false,
"responsive": true,
ajax: {
url: 'http://lms.dev/admin/getFilesList',
data: function (d) {
d.id = '8',
d.type = 'App\Lesson'
}
},
columns: [
{data: 'checkbox', name: 'checkbox', "width": "20px"},
{data: 'picture', name: 'picture', 'className': 'text-center'}
]
});
Run Code Online (Sandbox Code Playgroud)
如您所见,type发送到服务器的参数包含\(反斜杠)字符.但当我在Laravel中检索它时,后端的反斜杠字符被删除了.
什么是问题,为什么要删除?
我需要在节点中使用哪个标志fs.createWriteStream来创建具有755权限的文件.
我认为我们可以使用alert('foo')而不是window.alert('foo')因为在浏览器上下文中,this = window默认情况下,所以alert('foo')会自动表示this.alert('foo')哪个等价window.alert('foo').
所以,我没想到的alert功能,在一个函数中定义严格模式,因为当启用了严格模式,this是undefined在功能.
这是代表我的困惑的代码.
function foo() {
console.log('----- foo -----')
console.log('this: ' + this);
console.log('window: ' + window);
console.log('alert: ' + alert)
console.log('window.alert: ' + window.alert)
console.log('this.alert: ' + this.alert)
}
function bar() {
'use strict'
console.log('----- bar -----')
console.log('this: ' + this); // this is undefined
console.log('window: ' + window);
console.log('alert: ' + alert) // how is alert defined when …Run Code Online (Sandbox Code Playgroud)我正在尝试创建一个新的反应项目并使用以下命令
npx create-react-app login
Run Code Online (Sandbox Code Playgroud)
安装失败,提示“在“npm”注册表中找不到包“react””。
信息:
npx create-react-app login
Run Code Online (Sandbox Code Playgroud)