我如何获得已检查商品的价格和名称?
static func findLinesContaining(_ searchTerms: String, forSearchScope scope: SearchScope) throws -> [TextLines] {
guard let db = SQLiteDataStore.sharedInstance.TextDB else {
throw DataAccessError.datastore_Connection_Error
}
// TODO: convert to SQLite.swift syntax rather than using a SQL string
var statement: Statement? = nil
switch scope {
case .wholeCollection:
statement = try db.run("SELECT bookId, chapterId, lineId, lineText" +
" FROM lines" +
" WHERE rowid IN (SELECT docid FROM fts_table" +
" WHERE fts_table MATCH ?);", searchTerms)
case .singleBook(let chosenBookId):
statement = try db.run("SELECT bookId, chapterId, lineId, lineText" +
" FROM lines" +
" WHERE rowid IN (SELECT docid FROM fts_table" +
" WHERE fts_table MATCH ?) AND bookId = ?;", [searchTerms, chosenBookId])
}
var returnList: [TextLine] = []
for row in statement! {
let line = TextLine()
if let bookId = row[0] as? Int64,
let chapterId = row[1] as? Int64,
let lineId = row[2] as? Int64,
let text = row[3] as? String {
line.bookId = Int(bookId)
line.chapterId = Int(chapterId)
line.lineId = Int(lineId)
line.lineText = text
}
returnList.append(line)
}
return returnList
}
var total = 0;
function test(item) {
if (item.checked) {
total += parseInt(item.value);
} else {
total -= parseInt(item.value);
}
//alert(total);
document.getElementById('Totalcost').innerHTML = total + " ";
}
因为这只是<input type="checkbox" name="check_list[]" value="5" onClick="test(this);"><label>- Flag A</label>
<- <span class="badge">Price: 5 credits</span><br />
<input type="checkbox" name="check_list[]" value="13" onClick="test(this);"><label>- Flag B</label>
<- <span class="badge">Price: 13 credits</span><br />
<input type="checkbox" name="check_list[]" value="9" onClick="test(this);"><label>- Flag C</label>
<- <span class="badge">Price: 9 credits</span><br />
<button type="button" class="btn btn-primary">Tototal price: <span class="badge"><span id="Totalcost">0</span></span> credits</button>
,我想要显示名称和价格value="..."
或id
答案 0 :(得分:0)
这样的事情: 你需要用&#34; id&#34;标记你的标签。和您输入的属性&#34; data-index&#34;。这不是一个完整的解决方案,因为你仍然需要处理取消选中操作,尽管如果你学习的话,你可以从这个例子开始。
var total = 0;
function test(item) {
if (item.checked) {
var label = document.querySelector('#label'+ item.dataset.index);
total += label.innerText + " - " + parseInt(item.value) + " credits; ";
}
//alert(total);
document.getElementById('Totalcost').innerHTML = "Labels selected: " + total;
}
&#13;
<input data-index="1" type="checkbox" name="check_list[]" value="5" onClick="test(this);">
<label id="label1">- Flag A</label>
<- <span class="badge">Price: 5 credits</span><br />
<input data-index="2" type="checkbox" name="check_list[]" value="13" onClick="test(this);">
<label id="label2">- Flag B</label>
<- <span class="badge">Price: 13 credits</span><br />
<input type="checkbox" data-index="3" name="check_list[]" value="9" onClick="test(this);">
<label id="label3">- Flag C</label>
<- <span class="badge">Price: 9 credits</span><br />
<button type="button" class="btn btn-primary">Tototal price: <span class="badge"><span id="Totalcost">0</span></span> credits</button>
&#13;
答案 1 :(得分:0)
<强>更新强>
@Beytulla,这适合我。
<html>
<head>
<script>
function buttonClick(){
var total = 0;
var type = "";
for(var i=1;i<=3;i++) {
var id = "check_list" + i;
var label = "label" + i;
var badge = "badge" + i;
if (document.getElementById(id).checked!=null && document.getElementById(id).checked==true) {
total += parseInt(document.getElementById(id).value);
type += document.getElementById("label"+i).innerHTML + " : " + document.getElementById("badge"+i).innerHTML + ",";
}
}
document.getElementById('Totalcost').innerHTML = total;
document.getElementById('individual').innerHTML = type;
}
</script>
</head>
<body>
<form method="post">
<input type="checkbox" name="check_list1" id="check_list1" value="5" onClick="buttonClick(this);"><label id="label1"> Flag A</label> <span class="badge" id="badge1">Price: 5 credits</span><br />
<input type="checkbox" name="check_list2" id="check_list2" value="13" onClick="buttonClick(this);"><label id="label2"> Flag B</label> <span class="badge" id="badge2">Price: 13 credits</span><br />
<input type="checkbox" name="check_list3" id="check_list3" value="9" onClick="buttonClick(this);"><label id="label3"> Flag C</label> <span class="badge" id="badge3">Price: 9 credits</span><br />
<button type="button" class="btn btn-primary" onclick="buttonClick()">Total price:
<span class="badge"><span id="Totalcost">0</span></span> credits (<span id="individual">0</span>)</button>
</form>
</body>
</html>
答案 2 :(得分:0)
我如何获得小计用php需要检查用户是否有小计学分,如果他已将mysql发送到数据库并删除小计=学分 所以我试试这个
<script>function basket(item) {
if (item.checked) {
subtotal = subtotal + parseInt(item.value);
var basketItem = document.createElement('div');
basketItem.id = "Basket_" + item.id;
basketItem.innerHTML = "<span class='badge'>Toplam tıklama sayısı: <span class='badge' style='background-color:red;'>" + item.id + "</span> == " + item.value + " credits</span> ";
document.getElementById('Yetkiler').appendChild(basketItem);
} else {
subtotal = subtotal - parseInt(item.value);
document.getElementById('Basket_' + item.id).remove();
}
document.getElementById('subtotal').innerHTML = "<button type='button' class='btn btn-primary'>Total: <span class='badge'>" + subtotal + " credits</span>";
}
</script>
&#13;
<?php
$price1 = "10";
$price2 = "20";
$price3 = "30";
how i do this
if($user['kredits'] > here subtotal){
?>
<form method="post">
<input id="150" type="checkbox" name="max_clicks" onClick="basket(this);" value="<?php echo "".$price1."";?>" />
<label for="150">150 Tık</label><- <span class="badge">Fiyat: <?php echo "".$price1."";?> kredi</span>
<br/>
<input id="400" type="checkbox" name="max_clicks" onClick="basket(this);" value="<?php echo "".$price2."";?>" />
<label for="400">400 Tık</label><- <span class="badge">Fiyat: <?php echo "".$price2."";?> credits</span>
<br/>
<input id="735" type="checkbox" name="max_clicks" onClick="basket(this);" value="<?php echo "".$price3."";?>" />
<label for="735">735 Tık</label><- <span class="badge">Fiyat: <?php echo "".$price3."";?> credits</span>
<br/>
<div id="Yetkiler"></div>
<span id="subtotal"></span>
<input class="btn btn-success" style="float:right;" type="submit" name="add_ad" value="Reklam satın al"
</form>
<?php } ?>
&#13;