我想写这样的东西:
$widthXl: 1000px
$widthSm: 500px
@mixin med ($prop, $xl, $sm)
@media (max-width: $widthXl)
&
$prop: $xl
@media (max-width: $widthSm)
&
$prop: $sm
a
@include med(width, 600px, 300px)
b
@include med(color, #000, #888)
Run Code Online (Sandbox Code Playgroud)
得到这个:
@media (max-width: 1000px) {
a {width: 600px}
b {color: #000}
}
@media (max-width: 500px) {
a {width: 300px}
b {color: #888}
}
Run Code Online (Sandbox Code Playgroud)
但是我的代码没有编译它.可能吗?
知道某人是否面临同样的问题会很有趣.
如果我删除属性,代码工作正常.但我想创建复杂的解决方案.
如何innerHTML
通过 JavaScript 中具有类的父元素访问没有类或 ID 的子元素?
它应该只text
在<b>
标签之间返回。
<div class="parent element">
<h5>
some other text<b>text</b>
</h5>
</div>
Run Code Online (Sandbox Code Playgroud) 如果其中一个变量值为1,我想将背景颜色设置为灰色,否则行背景颜色将为白色
但事情是当变量值为1时,则添加了行但不添加了内容.如果变量值为0,则所有操作都按预期工作
我试过以下代码:
function insertRow(value){
$('#invoiceTable').append(
value === 1 ? '<tr style="background-color: #ccc8cb">' : '<tr>'+
'<td> category </td>' +
'<td> material </td>' +
'<td> ups </td>' +
'</tr>'
);
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table id="invoiceTable" class="table table-bordered table-hover" >
<thead>
<tr>
<th>Category</th>
<th>Material</th>
<th>ups</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<input type=button value='insert ash row' onclick='insertRow(1)'/>
<input type=button value='insert white row' onclick='insertRow(0)'/>
Run Code Online (Sandbox Code Playgroud)
请指出我做错了什么.
<div id="parent">
<div id="child1">
<div id="child2">
<div id="child3">
<div id="child4">
</div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何获取父元素,即如果我将目标节点作为然后child3
需要将父元素获取为child2
,child1
和parent。有没有什么方法可以在 JavaScript 中从子元素获取父元素。谁可以帮我这个事?谢谢。
我正在构建一个星球大战搜索应用程序,其中我有一个充满星球大战角色信息的对象,您可以使用与其匹配的地图函数动态搜索对象,该正则表达式在用户搜索角色时触发.
这一切都很完美,但我添加了用户点击角色(例如Luke Skywalker)的功能,然后将HTML添加到视图中并添加有关Luke的信息.我很难让这个功能只触发一次,用户可以在角色上多次点击,它会继续添加相同的内容.
我怎样才能让用户点击<li>
一次,这样功能displayInfo()
就会触发一次.
谢谢您的帮助.
var newView = document.querySelector(".starwars");
function displayInfo() {
newView.innerHTML += `
<div class="jedi">
<div class="image-wrapper">
<img id="swImage"src="img"
class="thumb reserved-ratio" alt="Luke Skywalker">
</div>
<div class="desc-sizer">
<p class="desc">Luke Skywalker was a Tatooine farmboy who rose from humble beginnings to become one of the greatest Jedi the galaxy
has ever known.
</p>
</div>
</div>
`;
searchInput.value = 'Luke Skywalker';
searchInput.addEventListener("focus", displayMatches);
searchInput.focus();
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用JavaScript练习对象和属性。我尝试将其插入innerHTML中,但所需的输出${item.img}
以字符串形式而不是实际图像显示。我也尝试将代码在notepad ++中的不同行中分开,但是除非在一行中键入,否则编译器无法识别该代码。请为此提供解决方案。
这是JavaScript代码:
const item = {};
item.img = 'img-cart${partPath}';
let name = event.target.parentElement.parentElement.nextElementSibling
.children[0].children[0].textContent;
item.name = name;
let price = event.target.parentElement.parentElement.nextElementSibling
.children[0].children[1].textContent;
let finalPrice = price.slice(1).trim();
item.price = finalPrice;
const cartItem = document.createElement("div");
cartItem.classList.add(
"cart-item",
"d-flex",
"justify-content-between",
"text-capitalize",
"my-3"
);
problem is here ----> cartItem.innerHTML = '<img src="${item.img}" class="img-fluid rounded-circle" id="item-img" alt=""><div class="item-text"><p id="cart-item-title" class="font-weight-bold mb-0">${item.name}</p><span>$</span><span id="cart-item-price" class="cart-item-price" class="mb-0">${item.price}</span></div><a href="#" id="cart-item-remove" class="cart-item-remove"><i class="fas fa-trash"></i></a></div>';
Run Code Online (Sandbox Code Playgroud) 首先,我必须验证 id 和密码文本框不为空(那个正在工作)。然后我必须在相同的表单上验证文本框上的 id 需要是一个数字,并且也是一个介于 3000 和 3999 之间的数字(那个不起作用)。关于我的代码有什么问题的任何想法?
function validatefunctions() {
if (document.getElementById('idtb').value === '') {
alert('You need to enter a Customer ID');
return false;
}
if (document.getElementById('pwtb').value === '') {
alert('Please enter your password');
return false;
}
var custID;
custID = document.getElementsByName("idtb").valueOf();
if (custID !== isNan) {
alert("Customer ID needs to be numeric");
return false;
}
if (custID < 3000) {
alert("ID must be above 3000");
return false;
}
if (custID > 3999) {
alert("ID must be below …
Run Code Online (Sandbox Code Playgroud) 我有一些 HTML 内容保存为字符串。
我想遍历该字符串中的每个标题标签并获取其内部文本。
let str = `<h1>topic 1</h1><p>desc of topic 1</p><h1>topic 2</h1><p>desc of topic 2</p>`;
const innerHTMLarr = str.match(/<h1>(.*?)<\/h1>/g).map(x => x);
console.log(innerHTMLarr)
Run Code Online (Sandbox Code Playgroud)
数组返回整个标题文本,如何只获取内部文本?
不介意使用 jQuery。
function checkEmail(str){
var emailCheck = /[^a-z][0-9]/;
if(emailCheck.test(str)){
console.log("**Its Valid Mail");
}
else{
console.log("Its not Valid");
}
}
var x = '122a';
checkEmail(x);
Run Code Online (Sandbox Code Playgroud)
我一直在学习正则表达式.从上面的代码我理解,x
不应该包含小a-z
,它必须包含数字,因为你可以看到122a
包含数字和小写字母a
,我认为它应该是无效的,但我得到它有效.任何人都可以解释我在想错的地方.
我不擅长RegEx.虽然看起来很容易实现,但我无法找到匹配任何字符后跟不是数字的方法.我正在尝试消极前瞻.如果我使用任何单词它按预期工作,但如果我尝试匹配任何字符与方括号,它是失败的.
var pattern = /sample(?!\d)/;
console.log(pattern.test("sample324")); //false
var pattern = /[a-z]+(?!\d)/;
console.log(pattern.test("sample324")); //true but expect false
Run Code Online (Sandbox Code Playgroud)
提前致谢.
javascript ×9
html ×3
regex ×3
function ×2
css ×1
ecmascript-6 ×1
frontend ×1
jquery ×1
sass ×1
validation ×1