我有一个JQuery,Javascript,超文本标记语言的网站。我做了一个简单的函数来删除文本,如果它不等于0。
该函数似乎起作用了,但页面中的其他所有内容都消失了。我只看到我的带条纹的文字。
应该删除productPrice,而不删除salePrice ...该函数可以工作,但布局会变得混乱。帮帮忙?
文本在我的页面上显示如下:
<label id="productPrice">Price</label>
<label id="salePrice">Sale Price</label>这里是代码,我可以提供更多,如果需要。
函数
if (product.price != 0);
{
var salePrice = product.price;
document.write(salePrice.strike());
}数组
var catalog = {"products": [
{"thumbnail": '/pub/3/resources/ti/store/mobile/chrome.png',
"brand": "Google",
"name": "Chrome",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"rating": '5',
"sale_price": "0.00$",
"sale_desc": "",
"price": "0.00$"},参数
$('#productPrice').html(product.price);发布于 2011-07-08 01:43:00
document.write()将从页面中删除除您编写的内容之外的所有内容。这就是它的工作原理。你现在可以试一下了,把javascript: document.write("Gone");放到你的地址栏里,页面就会以同样的方式消失。
另外,if语句后面有一个分号,所以您的代码将始终运行。
if (product.price !== 0) {
document.getElementById('productPrice').style.textDecoration = 'line-through';
}或
if (product.price !== 0) {
$('#productPrice').css('text-decoration', 'line-through');
}https://stackoverflow.com/questions/6614741
复制相似问题